This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes JSF and the fly likes Accessing an Excel file inside a WAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Accessing an Excel file inside a WAR file" Watch "Accessing an Excel file inside a WAR file" New topic

Accessing an Excel file inside a WAR file

Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Hello All,

I don't know where to place this appropriately, so I'll just post it here. I have an Excel file that I packaged with my WAR file, which I am using as a template for a certain download. When the user clicks a button, this file is read and it's content is saved as a downloaded file. The thing is, I am having problems accessing the Excel file. It seems like I cannot read the file inside the WAR. I tried accessing the same file, now saved in a directory outside of my WAR file, and the file is downloaded correctly. Does anybody out there knows how to correctly access a file inside a WAR file?

Thanks in advance.

There's so much to learn in this industry, and not everybody has the necessary interest.
Alex Sotin

Joined: Dec 19, 2006
Posts: 21
hi, please put here part of your code, where you're trying access to your excel file.

<a href="" target="_blank" rel="nofollow">Java Planet</a> <br />-- <a href="" target="_blank" rel="nofollow">Java Index</a>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303

I had an app like that. I think you should be able to treat the spreadsheet like it was an ordinary HTML or JSP page. Only problem you might have is in MIME types, where the user's browser might decide to do something with it.

However, in my app, I had to write a servlet that opened the file as a Java resource and copied it to the response stream. I think that was so I could add custom headers to the response stream.

Customer surveys are for companies who didn't pay proper attention to begin with.
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Thanks guys. I was able to resolve the issue. Thanks for your input.
I agree. Here's the link:
subject: Accessing an Excel file inside a WAR file