Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obtain ServletContext from Request

 
Jeff Black
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a bean that I only pass HttpServletRequest into, how can I obtain a reference to it's corresponding ServletContext?
I want the bean to be able to get at the ServletContext.getInitialParameter() method.

Jeff
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext sc = req.getSession().getServletContext();
 
Jeff Black
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No such method session.getServletContext() for servlet 2.2 API. I've already scanned the javax.servlet... API and there is no direct route to get the servletContext. Surely there must be another way?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted a similar question a while back. The getServletContext() method on HttpSession is new in Servlet 2.3. Apparently under 2.2 there's no way to get the context given just a request, and we must resort to passing it around with the request, or adding it to the request as an attribute before passing the request around. Ick.
hth,
bear
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic