wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP save as Excel File after displaying data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP save as Excel File after displaying data " Watch "JSP save as Excel File after displaying data " New topic
Author

JSP save as Excel File after displaying data

Peter Locascio
Greenhorn

Joined: Jun 05, 2009
Posts: 2


Greetings All Java gurus.

Ive got a page thats been making me

I have a JSP that is returning results from the users entered search criteria on a previous page

I would really like to make a button that would allow the user to save the file as either .xls or .csv

I thought I was on the right track with this header....

<%response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment;filename=report.xls");%>

once the user clicks RUN on the search page... the results page opens up and the user is prompted to either save the file on there desktop or cancel.. If the user saves the file you get the page output in the excel file perfectly .... But the data is not displayed on the JSP and the users want both

I thought maybe I was on the right track by making a javascript function and making the button onclick = openWin() to call that Content header.... but still the header activates as soon as the page runs so you dont even see the data on the page

anyone that can help point this greenhorn in the right direction Would just make my day

Thank you and GodSpeed

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

Two requests, not one.

Send the data to the JSP and use modern JSP techniques to display the data. In script, trigger a new request with the headers set to cause the save dialog to appear.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

P.S. By "modern JSP" I mean JSTL and EL, not scriptlets.
Peter Locascio
Greenhorn

Joined: Jun 05, 2009
Posts: 2
My apoligies im still a greenhorn
this is not a JSP that i created personally it came from an outsourced company that built the applicatiion. Im just trying to modify it.

can you please elaborate some more ?

Thank you and GodSpeed
sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 179
Hi,
Display the data using the JSP either scriptlets or the modern approach. Have a hyperlink/button on the JSP page , when the user clicks link/button, it will initiate a new request with the header set to open the save dialog box.
Thanks
Sudha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

sudha swami wrote:Hi,
Display the data using the JSP either scriptlets or the modern approach. Have a hyperlink/button on the JSP page , when the user clicks link/button, it will initiate a new request with the header set to open the save dialog box.

Why bother with the link when the request can be automatically triggered?
sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 179
Bear,
Thanks for the info.
Just wanted to know, How it can be done? Do i need to use AJAX?
Sudha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

sudha swami wrote:Do i need to use AJAX?

This is not your post. Please do not hijack other people's post with you own issues. Start a new post if you have questions of your own.

But, no, Ajax is not necessary. (Though to trigger it automatically, JavaScript is.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP save as Excel File after displaying data