We are developing a JSP/Servlets web application and cannot find how to retrieve the web application root dynamically at the Start Up of the Web Application (i.e. before any requests have been created so we cannot use methods from the request object).
We need to have this app root at the application startup, because it is widely used inside the JSP pages and the servlets of the web application. Also we would like to avoid setting it as a static parameter in the web.xml or elsewhere.
Does anyone know how to do that? Any hint or suggestion is very much appreciated!
If I understand what you are after, in the init method of a servlet you get ServletContext which has various methods such as getResourcePaths() that might help. Bill
Joined: Feb 27, 2002
I've retrieved and inspected the servletContext object in my Start Up servlet and although the context path can be viewed as a variable there does not seem to be a method to extract it and use it within a program.
Once a request object has been created then the getContextPath method can be used to retrive the path but we require the value before any requests have been created.
hi all, I don't know whether this topic still watched by you all.
What I would like to ask is, getRealPath() will return the exact location for the file such "C:\jboss\server\default\deploy\myWebApps". Is that a method that we can use to return only "/myWebApps"?
The purpose for me to doing this is to get the context path (says '/myWebApps') and append it with my images location (eg, '/myWebApps/images/'). It would be inappropriate for me to show the exact location to my users. (eg. 'C:\jboss\server\default\deploy\myWebApps\images').