1

I have a web application where the context name is different from my root name. For example my root Dir name is myapp and the context path is app. Then how to get the root name (myapp) from the Java web application?

Netorica
  • 18,523
  • 17
  • 73
  • 108
AnilHoney
  • 259
  • 8
  • 20

1 Answers1

5

If the application is not deployed with a war file you can use this code that will return the whole address where the application is running.

//request variable is the Java HTTP servlet request object received from an action 
request.getSession().getServletContext().getRealPath("/");

The code I had given is the one I used in one of my Java EE projects well I didn't deploy my project as a war file due to some reasons

and getting the web application location can be used to get your root directory name

Netorica
  • 18,523
  • 17
  • 73
  • 108
  • OK lets give my side pre-conditions i have a webapplication that used some what context name in logic where root name and context name both are same but now context name is changed to root but dependency with context name. – AnilHoney Dec 29 '12 at 13:52