• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP save as Excel File after displaying data

 
Peter Locascio
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. By "modern JSP" I mean JSTL and EL, not scriptlets.
 
Peter Locascio
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic