mookie13
asked on
Get Working directory in JSP
Hi all,
I have multiple JSP's and each one sits in a different directory with various images and such. My JSP outputs the contents of the directory along with some other information. Right now this only works if I hard code the directory path in the JSP.
I need to be able to have the path to the current working direcotry dynamically generated by the JSP. Is there a way to do this?
I have multiple JSP's and each one sits in a different directory with various images and such. My JSP outputs the contents of the directory along with some other information. Right now this only works if I hard code the directory path in the JSP.
I need to be able to have the path to the current working direcotry dynamically generated by the JSP. Is there a way to do this?
ASKER
Not exactly. This gives me the full path on the web server. In other words, it's returning this:
c:\WebSites\resin-3.0.18\w ebsites\RO OT\folder1
I'm only looking for the directory relative to the site root. So I want it to return:
/folder1
or
/folder2 (depending on where this JSP is living.)
So I can build the link to the file:
/folder1/myImage.jpg
Right now it's doing this:
c:\WebSites\resin-3.0.18\w ebsites\RO OT\folder1 \myImage.j pg (which, of course, breaks.)
Thanks for your time in helping!!!
c:\WebSites\resin-3.0.18\w
I'm only looking for the directory relative to the site root. So I want it to return:
/folder1
or
/folder2 (depending on where this JSP is living.)
So I can build the link to the file:
/folder1/myImage.jpg
Right now it's doing this:
c:\WebSites\resin-3.0.18\w
Thanks for your time in helping!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i think you can use something like:
<%
String path = request.getContextPath();
%>
<%
String path = request.getContextPath();
%>
ASKER
I do believe this works now!! Yay! Thank you!!
Your welcome, if you are talking to me. rrz
<%
String pathToJsp = application.getRealPath(re
File jspFile = new File(pathToJsp);
String parentPath = jspFile.getParent();
%>
<%=parentPath%>