wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes how to keep the filename when client opens a streamed file in browser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to keep the filename when client opens a streamed file in browser?" Watch "how to keep the filename when client opens a streamed file in browser?" New topic
Author

how to keep the filename when client opens a streamed file in browser?

Henry Leung
Greenhorn

Joined: Oct 26, 2003
Posts: 24
When streaming an excel file to client, how to let client opens it directly in IE without losing the filename I specified?




I am writing a struts webapp. When user clicks a particular button, the html form will be submitted to http://mydomain.com/mywebapp/getreport.do. An excel file will then be streamed to user. User can choose to open it directly in IE, or save it.

This is how I set the http header in the Action class:


It works fine. User will be prompted to open or save the file. The filename myexcelfile.xls is displayed in the prompted dialogue box. If user chooses to save, myexcelfile.xls will be the default filename.

However, if user chooses to open it, the filename myexcelfile.xls will be lost. The excel file will be directly opened in IE. If user clicks File --> Save As, the default filename provided will be getreport.do.

I don't want this to happen, because such a filename (getreport.do) might confuse the user. Does any know a solution?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60743
    
  65

You're doing what you can on the server side. The rest is up to the browser. I've moved this to the HTML forum which as close to a "deal with browser issues" forum as we have.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I do not think you have any control over this situation.

Eric
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
1. if you have access to your server configuration, you should be able to define an alias for your "getreport.do" and call it whatever you want.

2. Depending on your server abilities and traffic you expect, you may have an option of creating a temp file on you server, naming it whatever you want, write report into it and provide it to user.
Henry Leung
Greenhorn

Joined: Oct 26, 2003
Posts: 24
Originally posted by Yuriy Fuksenko:
1. if you have access to your server configuration, you should be able to define an alias for your "getreport.do" and call it whatever you want.

2. Depending on your server abilities and traffic you expect, you may have an option of creating a temp file on you server, naming it whatever you want, write report into it and provide it to user.


Thanks for your suggestions.

I thought of option1 before. It is rather tricky and would add difficulty to the webapp's maintainability in the future. So I took it as a last resort.

For option2, I don't prefer it because it induces another problem about how to control user's accessibility to a physical file on disk. By streaming through a servlet, the servlet can use the user-setting of the webapp.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to keep the filename when client opens a streamed file in browser?
 
Similar Threads
opening the excel sheet from servlet
how to keep the filename when client opens a streamed file in browser?
two prompts for jsp content ported to msword
IE file save as
Open CSV file in Excel not IE