SaveAs Dialogue box is not working on button click in servlet

SaveAs Dialogue box is not working on button click in servlet

Hii Sir, i added response.setHeader into my servlet code to export the data into excel file but this is not working on button click ...plz give me the write code. Thank you Sir.

response.setHeader("Content-Type", "application/vnd.ms-excel"); response.setHeader("Content-Disposition","attachment; filename=excel.xls");

String datum1 = request.getParameter("fromdate");
String datum2 = request.getParameter("todate");
SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MM-yyyy");
Date date = sdfSource.parse(datum1);
Date date2 = sdfSource.parse(datum2);
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
datum1 = sdfDestination.format(date);
System.out.println(datum1);
datum2 = sdfDestination.format(date2);
System.out.println(datum2);


HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("CallBillingSystem");

HSSFRow rowhead = sheet.createRow((short) 0);
rowhead.createCell((short) 0).setCellValue("calldate");
rowhead.createCell((short) 1).setCellValue("src");
rowhead.createCell((short) 2).setCellValue("dst");
rowhead.createCell((short) 3).setCellValue("dstchannel");
rowhead.createCell((short) 4).setCellValue("lastapp");
rowhead.createCell((short) 5).setCellValue("duration");
rowhead.createCell((short) 6).setCellValue("disposition");
rowhead.createCell((short) 7).setCellValue("amaflags");
rowhead.createCell((short) 8).setCellValue("cdrcost");


String strQuery = "";
ResultSet rs = null;

conexion conexiondb = new conexion();
conexiondb.Conectar();

strQuery = "SELECT * FROM cdrcost where date(calldate) between '" + datum1 + "' and '" + datum2 + "'";

 //strQuery = "SELECT * FROM cdrcost where date(calldate) between '2011-09-01' and '2012-01-01'";

rs = conexiondb.Consulta(strQuery);
int i = 1;
while (rs.next()) {
    HSSFRow row = sheet.createRow((short) i);
    row.createCell((short) 0).setCellValue(rs.getString("calldate"));
    row.createCell((short) 1).setCellValue(rs.getString("src"));
    row.createCell((short) 2).setCellValue(rs.getString("dst"));
    row.createCell((short) 3).setCellValue(rs.getString("dstchannel"));
    row.createCell((short) 4).setCellValue(rs.getString("lastapp"));
    row.createCell((short) 5).setCellValue(rs.getString("duration"));
    row.createCell((short) 6).setCellValue(rs.getString("disposition"));
    row.createCell((short) 7).setCellValue(rs.getString("amaflags"));
    row.createCell((short) 8).setCellValue(rs.getString("cdrcost"));
    i++;
}
FileOutputStream fileOut = new FileOutputStream(filename);
hwb.write(fileOut);     
hwb.write(response.getOutputStream());
System.out.println("Your excel file has been generated!");
FileOut.close();

} catch (Exception ex) { System.out.println(ex);

}

}

View Answers









Related Tutorials/Questions & Answers:
SaveAs Dialogue box is not working on button click in servlet
SaveAs Dialogue box is not working on button click in servlet  Hii Sir, i added response.setHeader into my servlet code to export the data into excel file but this is not working on button click ...plz give me
get a radio button click value - JSP-Servlet
get a radio button click value  thanks sir for sending code ,but i...") in servlet that is used in another jsp so can i call getParameter("radio") i.e... servlet from another jsp i.e 'main.jsp', then you have to store the value of id
Advertisements
on click button php
on click button php  Function in PHP for on click button
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
css click box
css click box  I wanted to create a click box in CSS with a hyperlink that should appears flat.   Find the below given code.. In your HTML file .. click box Text CSS a { display:inline-block; width:30px
passing values on button click
passing values on button click  Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
iphone button click event
iphone button click event  Hi, How to write iphone button click event? Thanks   Hi, Here the method declaration: -(IBAction) myMetod...{ NSLog(@"Button clicked"); } Thanks
jquery button click
jquery button click  jquery button click - I have created a button in JQuery but the problem is that it's not detecting click. What could... to create a button event in JQuery. You can edit it as per your requirement. In Header
java swing button click event
java swing button click event  java swing button click event   public void doClick()   Java Swing Tutorials
JFrame Button click to start play
JFrame Button click to start play  i made a game and and i add a button in new jframe and i want when i click it it start to play...can anyone help me
Call a servlet on click of hyperlink
Call a servlet on click of hyperlink  Call a servlet on click... the servlet url of desired servlet as href="<%=request.getContextPath()%>/CallServlet? . CallServlet is the url of the Servlet. <html>
SubCombo box not working - Development process
SubCombo box not working  Hi, in the following code subcombo box is not working and while storing combo box numbers(1,2,3) are stored instead of values. Search Page var arr = new Array(); arr[0] = new
On click Checkbox values displayed in text box
On click Checkbox values displayed in text box  Hi sir, If i onclick the checkbox values should be displayed in text box, the following code is working properly in Internet Explorer browser but its not working in Google chrome
On click Checkbox values displayed in text box
On click Checkbox values displayed in text box  Hi sir, If i onclick the checkbox values should be displayed in text box, the following code is working properly in Internet Explorer browser but its not working in Google chrome
How to add download option for openwith and saveAs on exporting file to excel in servlet
How to add download option for openwith and saveAs on exporting file to excel in servlet  Hii Sir, I made an application in which i need to export... my requirement I need to give download option for openwith and saveAs from
How to add download option for openwith and saveAs on exporting file to excel in servlet
How to add download option for openwith and saveAs on exporting file to excel in servlet  Hii Sir, I made an application in which i need to export... my requirement I need to give download option for openwith and saveAs from
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Browser Back Button click event javascript
Browser Back Button click event javascript  I am using the below code but window.onBeforeUnload is not working with back button.. how can i apply the below code for the click event of back button? window.onBeforeUnload
On Click on Submit Button Display Data on Orderlist
On Click on Submit Button Display Data on Orderlist  How can retreive data from database on orderlist on Click on submit Button of same page
Click on Page Refresh - JSP-Servlet
Click on Page Refresh  hi ,i am working on jsp with mysql. i m facing a problem whenever i click on page refresh or f5 button, the value on form... the condition in which record insert in the database only when the "submit button
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
click on back button go to the login page
click on back button go to the login page  now when i click on back button the page show that page on where i came from and it shows the session expired but i want when i click a back buttob then it should show a login page
JSP view detail page on accept button click
JSP view detail page on accept button click  i Have 1 jsp page in that there r 2 button accept and view details when we click on aceept button it will submit to next page and when click on view details page it will shown the data
Click On Images of Submit Button Perform Action
Click On Images of Submit Button Perform Action  I have login page in which insert of submit button i used image. Therefor on Click of image i have to validate form , link with database and goto the next page
print form information when click on print button
print form information when click on print button   Sir,I desingn institute webside using jsp and strut by using platform netbean 7.2.So request you please help for printing form information by clickin print button after submit
next button in servlet
next button in servlet  i want to add next,previous button to get next record in my servlet. can you explain the logic to do
Open website on Button Click - Java Beginners
Open website on Button Click  Hello sir I want to open website on button click using java swing plz help me sir. in my swing application one "VISIT US BUTTON" i want to open my website on Button CLick  Hi Friend
iPhone Button Click Sound
iPhone Button Click Sound In this series of iPhone button tutorial, we... the application to listen the sound on button click. The sound file that i have used... on clicking the button in iPhone SDK. For the audio we are going to use
Servlet signup still not working satisfactorialy - JSP-Servlet
Servlet signup still not working satisfactorialy  Hello sir thanks for your reply I tried following code given by you, What it has a problem as: I... signup /SignUp   Hi friend, Code for Servlet
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
How to check for Empty textboxed and fill it with a value on a button click
with a Button beside it . when i enter a text in that box and click the button it should go.... the button should be disabled once i click it(i managed to do that), but when i'm... click. When you enter a text in a textbox and click the button, it will get added
Expand / Collapse form div when click on button
Expand / Collapse form div when click on button  Hi, I have a form integrated from Wufoo with iFrame code. If the user misses a field an error message appears but it takes more space than the DIV Formbox. How can I make the DIV
List Box - JSP-Servlet
list box.on selecting one value in list box,i will retrieve values from database and store into another list box in same page using javascript :location.my problem is in first list box,value which i selected to get values is not displaying
change database values when click next button on jsp page
change database values when click next button on jsp page  How to retrive database values rondomly and display jsp page ,when user click next and previous bottons change the values on jsp page
Moving Div by button click using animate effect
Moving Div by button click using animate effect In this tutorial , we will discuss how to move 'div' left-right by button click using jQuery. In this example , 'div' is moving left / right by left / right button click
when i hit enter it represent action like click a button
when i hit enter it represent action like click a button  Hi, Plz provide a program in html like I want 2 submit buttons,when i hit the enter button it will represent the action like click the 1st submit
My Servlet code not working - Development process
My Servlet code not working  HHi, After executing servlet am getting blank screen. Am using weblogic server and Eclipse editor. But jsp is working fine. Steps(what i did ) 1)Created servlet (In eclipse) and export it (saved
List the names of classes used to create button and text box in Java.
List the names of classes used to create button and text box in Java.  List the names of classes used to create button and text box in Java
Download Button - JSP-Servlet
how to implement the download button so that on clicking that the mini
Session expire and back button in jsp and servlet .
Session expire and back button in jsp and servlet .  Hii Sir... previous pages by clicking back button of browser without again logging. Plz sir give me the full working code of this .It is the starting need of my project
Alert Box in Flex
is modal, which means it retains the focus until we close it or click on any button...;middle"> <mx:Button label="Click" click="ClickEvent()"... as follows will be shown on the screen. If we click Yes button, output
display uiactivityindicatorview on button click through notification ios 5
display uiactivityindicatorview on button click through notification ios 5  I wants to add a UIActivity Indicator view on UIView controller. Also i want to display a Activity indicator when a UIButton is click. I searched
create text box by clicking button and submittong text in text box using submit
create text box by clicking button and submittong text in text box using submit  Hi, I created a button when i click on button new textbox... will click submit button the text should be submitted(it shows the value in text
radio button selection should move the control to a text box that needs to be complete
radio button selection should move the control to a text box that needs to be complete  on selection of a radio button mouse should move to a particular text box that needs to be filled. How
how to add save,discard,& cancel button in a message box - Struts
how to add save,discard,& cancel button in a message box  how to add save,discard,& cancel button in a message box

Ads