• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP download  RSS feed

 
Ankit Pedro
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My jsp page contains a button which exports data to an excel sheet. The excel file is being saved on the server.
How can i save the file directly on the client.
[ June 16, 2005: Message edited by: Ankit Pedro ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i save the file directly on the client.


You cannot save it directly to the client. Think of the nightmare that would ensue if every server could just write whatever it wanted to your computer.

The viable approach is to offer the report for download. If the file exists on the server in a place accessible to the web server, this could be as simple as creating a link (using the <a> tag) to that file.

Otherwise, you could write a servlet that streams the file to the client after setting the correct content and disposition headers.
 
Ankit Pedro
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bear,

The case that I am facing is :

When the administrator checks a time sheet, a buton ( export to excel ) saves the time sheet on the client. The time sheet data are not in a file on the web server the are in a database.

I was thinking when pressing the button, the data first gets saved on the server as .xls file then downloaded to the client.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the content type (to tell the browser what kind of file this is).

Set the content disposition (to tell the browser what the name of the file is to be and whether to prompt for a location to save to 'attachment' or to open the associated application 'Excel' right in the browser 'inline'.

Then parse your data into delimited lines or an HTML Table).
[ June 17, 2005: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!