Is it possible to programmatically get the name of the web application from jsp/servlet?
I have a utility class that creates a url, I want to be able to dynamicaly get the name of the web app to pass into the class. For example:
if I want to create a url for the login page.
this will return the url of the login page, but if I am inside of a web application I want to be able to append the name to get
I usually have a properties or XML file with various application properties in it. However, there are many ways to do this. One of the most common properties that I use is the application name. As for getting the application name directly from the servlet engine, I don't know, never tried. Here is a good article be Sean Neville on how to use Properties files or XML files.
For what it sounds like you want, request.getContextPath( ) should get you what you need.
I am using web macro's as UI( this is the first time i am using and still learning) and servlets to do my back end job, i need to retrieve my servlet URl so that i can automate my app to run on any application server, i am able to retrieve the URI but not the URL from my request object, where am i doing wrong, i have tried all the possible combinations of methods but still finding it hard to achieve, help me out.
thanks for ur time
regarding the question how to retrieve URI of ur web app, from servlet/JSP
String URI = req.getRequestURI();
should do the job of identifying the servlet URI or ur web app path.
Thank you all for your responses.
The request.getContextPath() was exactly what I was looking for.