Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

routes  RSS feed

 
yara becker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!!

I have a doubt about the correct form to refer archives in my web application.I hope I can explain.
I need to use many xml archives in a folder that I have put in the place where I have the .jsp and I want to use a relative route because now I have to write the absolute direction.I don't know where these xml archive had to be.�Could you help me?

Thanks in advance (and again:"I'm sorry for my english")
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yara,
Your English is better than my (name a languge).

Have a look at the
getResourceAsStream method.
 
yara becker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Ben (you're very kind with my english :-))

So, if I've understood your suggest, I have to use a servlet if I want to use relative directions. I thought that there was some folder (for example, jboss/server/default/...)where I could put the files, and then use "http://localhost ort/FileName" like path.

thanks again
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a best practice never to do anything but format the look look and feel markup from within a JSP (Google "MVC" for more info).

That being said, no you don't have to do this from a servlet.
You could call this method from a JSP.
The implicit variable application points to the servlet context object. application.getResourceAsStream

The reason I recommend using getResource or getResourceAsStream is that J2EE apps don't necessarily correlate with the directory structure of the server's file system.

If you're app has been deployed as an exploded file system, you can find the file system path of any of your apps files with the ServletContext.getRealPath(filename) method. However, if your app is being run from a packed war file (as is the default in several containers) then that method will return null; since the file doesn't really exist outside of the zipped up war file.

The getResourceAsStream method will fetch the file for you regardless of how the app was deployed.

If you want to see an example of getResourceAsStream go to http://simple.souther.us and download SimpleStream.war.
This demo app uses getResourceAsStream to read image files from under the WEB-INF directory for streaming to the browser.
[ May 16, 2006: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!