• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Obtain ServletContext from Request

 
Greenhorn
Posts: 14
  • 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
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext sc = req.getSession().getServletContext();
 
Jeff Black
Greenhorn
Posts: 14
  • 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?
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
Just the other day, I was thinking ... about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic