SaveAs Dialogue box is not working on button click in servlet

Ads
 

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

Ads









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
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
Advertisements
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
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
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
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>
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
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
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
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
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
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
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
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
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
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
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

Ads