Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save excel file by hitting a url

 
berender mavi
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello all

I have a jsp page which is showing data in that page from DB.there is also a facility to show data in excel file.So there is a link to import the data in excel file.

I have noted down that url by pointing the cursor to that link that is also in the attached jpg file.Now i am hitting that url using url class but it will showing some jsp code,i think of that page in the ouput of java file.

But i want to save that data in excel file as it is occurring from GUI by clicking that icon.How can i save that file on the system by hitting that url.

SEE THE URL IN THE STATUS BAR OF ATTACHED JPG
Screenshot-1.png
SNAPSHOT OF JSP PAGE
[Thumbnail for Screenshot-1.png]
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to use a proper servlet for generating the Excel file, not a JSP file. The latter are not as good for binary data (which Excel files are).

I'll move this thread to our Servlets forum.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you want to just click on the link and have the data showing on your browser page to be saved in an Excel file. Unfortunately, it's not that simple. You must do the following:

1. When the user clicks the link, you need to send a request to the servlet.
2. The servlet gets the data from the database.
3. The servlet converts the data into a format that Excel can understand. This can be for example, true Excel format, comma-delimited or tabbed delimited, data. (For true Excel format see the Apache POI API.)
4. The servlet sends the data back to the browser not as HTML but as the Excel-formatted data. This is done by setting the Content-Type (and other fields) in the HTTP header of the HttpServletResponse
5. The browser will then receive the data and, depending on its settings, will display the data in Excel or offer to save the file, or something else.

I hope there are enough buzzwords in the above to start your google investigation.
 
berender mavi
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buddy actually my front end is doing the whole work to export data to excel file.but i want a write a java program that runs in background and automatically click on that link and save the excel.

there is no problem in my jsp page but i want to do it also from my java code so that automatically at a particular time excel file is downloaded on the system so no need to click on the link manually.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking how to generate the Excel file, or how to make the browser save the file without user interaction?

If you're asking for the later, for security reasons most browsers won't allow this. At best, you could have a "refresh" meta tag point to the generated Excel file. The user would likely be prompted to save the Excel file after the refresh timeout (unless they've sent their browser to automatically save that file type).
 
Krysthiam Diaz
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you want to just click on the link and have the data showing on your browser page to be saved in an Excel file. Unfortunately, it's not that simple. You must do the following:

1. When the user clicks the link, you need to send a request to the servlet.
2. The servlet gets the data from the database.
3. The servlet converts the data into a format that Excel can understand. This can be for example, true Excel format, comma-delimited or tabbed delimited, data. (For true Excel format see the Apache POI API.)
4. The servlet sends the data back to the browser not as HTML but as the Excel-formatted data. This is done by setting the Content-Type (and other fields) in the HTTP header of the HttpServletResponse
5. The browser will then receive the data and, depending on its settings, will display the data in Excel or offer to save the file, or something else.

I hope there are enough buzzwords in the above to start your google investigation.


Tom Reilly, what about if I'm using spring MVC? Is there any problem related to the spring context if I use a servlet to create my Excel file?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic