cassiej81
asked on
JSP, how to get real path of any file?
Hi,
My JSP page using a properties file call "config.properties" and i put it on WEB-INF.I used
getServletContext().getRea lPath("/") +"/WEB-INF /config.pr operties" to get the path to it, but how can i get the path to it without declare a detail path like that.Does Jsp/servlet have any function which can scan for a file and give us a real path?
Thanks in advance!
My JSP page using a properties file call "config.properties" and i put it on WEB-INF.I used
getServletContext().getRea
Thanks in advance!
ASKER
Thanks CEHJ, but it said null :((
And what i need is a function(or anything like this) which can return a full path of this file
i.e: getFilePath("config.proper ties"); it's return "/root/somedir/config.prop ertoes"
And what i need is a function(or anything like this) which can return a full path of this file
i.e: getFilePath("config.proper
OK what happens when you call the code you had yourself?
btw if you put your file in /WEB-INF/classes the code i posted should work
ASKER
it's will return the real path of my file. I ask this question because i dont' want to change the code(to a new path) if i put the config.properties on another folder. Any solution?
That can't be done - if you change the folder, you must change the code.
ASKER
Are you sure?
I still think there are have a function which can recursive all the folder and return the path of file, googling for it now
I still think there are have a function which can recursive all the folder and return the path of file, googling for it now
Well you could do that but it's messy. Why do you need to do this? Why not just put it in the same place each time?
ASKER
Hi CEHJ,
but if i put it in WEB-INF/classes/ , there're have another way to get it without include web-inf (getClass().getResourceAsS tream("/WE B-INF/conf ig.propert ies");) ?
but if i put it in WEB-INF/classes/ , there're have another way to get it without include web-inf (getClass().getResourceAsS
ASKER
btw, i also got the null when i use your code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, thanks CEHJ, i got it
:-)
InputStream in = getClass().getResourceAsSt
and read it