wood burning stoves 2.0*
The moose likes Servlets and the fly likes Redirecting to a generated excel file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirecting to a generated excel file" Watch "Redirecting to a generated excel file" New topic
Author

Redirecting to a generated excel file

Michael Crutcher
Ranch Hand

Joined: Feb 18, 2002
Posts: 48
I'm very new to servlets/jsp but have a strong java background. This is what I want to do:
1. Take input from an html page
2. Use this input to generate a sql query to the database.
3. Depending on user input output an html table or an excel table.
I don't have any problems with 1 or 2 or generating the html table. I've also successfully constructed an excel table (via jakarta POI, which is awesome btw) but I'm not sure how to display it. As I said I'm extremely new to servlets and I don't really know how to redirect to an excel document. I constructed the excel doc and have saved it on the webserver. What commands should I use to redirect to this document (it's within the same webapp as the servlet).
Any help would be greatly appreciated.
Thanks,
Michael Crutcher
Texas A&M University
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
If you really need to have the file, you could
include a link to it in the HTML page you send as a response to the user's input, of course the file would have to be placed where it could "legally" be served like any other file with a link.
Alternately you could use a link that pointed to your servlet and have the servlet send the file, that way the file could be anywhere.
Or you could create the file and serve it on the fly.
You would have to get the content type right so the browser would know what to do with it. I think there were more discussions of this around here recently.
Bill
Jesse Beaumont
Ranch Hand

Joined: May 30, 2002
Posts: 43
Hi,
The trick is simply to stream it back to the browser and set the content-type to be application/vnd.ms-excel. That way it should be picked up and displayed in Excel in the browser. Note also that you can stream an HTML table with that content type and have that table displayed in Excel, which removes the need for POI depending on how complex the spreadsheet is.


---<br />Time flies like an arrow,<br />Fruit flies like a banana
Michael Crutcher
Ranch Hand

Joined: Feb 18, 2002
Posts: 48
Thanks for your quick response. I'm going to just send back a link to the page for now. (that was to obvious for me to think of) I'd like to just pop it up, but I think I need to learn more first.
Thanks,
Michael Crutcher
Texas A&M University
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirecting to a generated excel file