Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Servlet Context without servlet

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to get the Servlet or application context for a class(which is not a servlet) running in web container ??
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well to get context of servlet you can use method getServletContext() which will return u the servlet context .
See the servelt documentation as this method is available in every servlet class so u can use it and see , I hope this would work.
Thanks
Jasbir
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if its running in a web container one would think it is called from a servlet, in which case you can pass the context object from the servlet to the other classes?
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to do that. It is called from servlet/JSP's but I want the class to be independent of that. i.e the class should be able to query something and get the servlet context
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a reference to ServletConfig in your class, you can use it to get the ServletContext.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is called from servlet/JSP's but I want the class to be independent of that. i.e the class should be able to query something and get the servlet context


Exactly what do you need from the servlet context? Perhaps there is a better way to get it.
It seems to me your requirements are incompatible - time for a redesign maybe. If you can make the class independent of the servlet environment, it will be easier to test.
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic