We can use ServletContext.getRealPath(), to get the absolute path of the given URL.
Example:-
<% String path = request.getRealPath("/");
out.println("Real path: " + path);
%>
Result:-
Real path: C:\Program Files (x86)\Apache Software Foundation\Tomcat 5.5\webapps\ROOT
Note that it does not necessarily work in all situations. For example, if your Tomcat is configured to deploy the .war file without unpacking it, then this will return null.
No comments:
Post a Comment