This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Context Root From Servlet Code

 
Andrew Cly
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In my servlet code I try to query the (deployed) context root of my
web application. By context root I mean that usually a http request
looks like this: http://host ort/contextroot/...

I tried to use ServletContext.getServletContextName() but it does not
work on Jboss and Tomcat servers I am using.

What I would do is to limit my web app to only be deployed under
certain context root. Otherwise my servlet will serve a http request
differently.

Is there a way to do this?
Thanks,
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check out the javadocs for HttpServletRequest, and in specific the getRequestURL method.

But of course you've done that already because you know that the API docs are your friend?
 
danny liu
Ranch Hand
Posts: 185
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext.getServletContextName() gets the display-name of that context. It may not be the real context path.

Use Request.getContextPath() method
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic