Solved

JSF How to load Files

Posted on 2004-10-20
3
606 Views
Last Modified: 2011-10-03
Well I have a little problem that cause me a lot of trouble.
I have created my first jsf web site based on xml files so in my java code I load those files and process it.
In the development phase the pats of the files was kind of hardcoded laike absolute path and now , when evrything else is done, I m having problem placing tis site on the server because I can found the way for loading Files with relative paths on the server.
I need just those one or two lines to get File from the public-html folder...

String sRoot = methodToGetRootFoolder();

0
Comment
Question by:cubrovic
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 12367694
<%
  URL theFile = pageContext.getServletContext().getResource( "/file/relative/to/webapp/root.txt" ) ;
%>

should do it?

ie:  if the files are in the webapp's root directory, then:

<%
  URL theFile = pageContext.getServletContext().getResource( "/file.txt" ) ;
%>

should return a URL for it (which you can then use to load the resource)
0
 
LVL 7

Author Comment

by:cubrovic
ID: 12555323
That's the way.
I have used getRealPath instead of getResource but that is it.
Thanks
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12555370
:-)

Glad I could point you in the right direction :-)

Good luck with it all :-)

Tim
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
grep code 4 153
runtime exception and error differences 4 63
How to Post an If Statement in JSP 3 45
oracle fusion vs MQ 2 91
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now