This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Correct Generated File Extensions from Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Correct Generated File Extensions from Action" Watch "Correct Generated File Extensions from Action" New topic

Correct Generated File Extensions from Action

Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
On our application we have to Produce many different csv files.

Right now we are using Strut Actions to produce these files. However, the file extension is always .do (How we have our actions mapped in the web.xml file.) Not very end user friendly.

I just tried to add the mapping of .cvs to the web.xml file and everything worked great, the csv was generated with a nice .csv extension. However, then we tested having a real .csv file on our server and we received a nice "The Requested Resource (blah, blah, blah) is not available."

My question is, how do you go about generating files on demand, but get the correct file extension for them? We are using a lot of csv, xml, and pdf file extensions.

In a different part of our application we actually generate the files and then provide a dynamic link the user so they can download those files from there server. However, we are looking for a solution where we can click the link, generate the data, and have the user save the file all in one shot.

Any ideas?

Thanks for your time,

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63232

Investigate usage of the content-type and content-disposition response headers.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81

Try these lines of code in your action:

response.setHeader("Content-Disposition", "inline; filename=wibble.csv");

Have you checked out Aspose?
subject: Correct Generated File Extensions from Action
It's not a secret anymore!