• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ServletContext outside the Servlet Container

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,
Is it possible to get the hold over ServletContext object outside the servlet container. I want to make the use of servletcontext in my POJO code to get some information stoired in this object. Is it possible to do that ? . Any link, white paper will be greatly appriciated.
Thanks in advance
Samir
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bad idea. You could pass a reference to the context to the POJO, but now that ties your POJO to the servlet environment and gives it access that it probably should not have. That's just plain poor design.

Rather, why does your POJO need this? Answer that and you could get a better way to accomplish your actual goal.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear
Thanks for the prompt reply. I have decleared some variables in web.xml which I are accessible through the ServletContext ,and I want to keep some custom object variable in sink with these values. These custom object I dont want to expose to servlet . If someone changes the values in web.xml , my custom object variable value also need to be changed. Writting a code of accessing the ServletContext in the POJO could suffice my need or otherwise please let me know the alternative solution for the same .
Thanks
Samir
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pass the values, not the servlet context, to the POJO.
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
While reading the post I had some questions so just thought of posting it.
1) If POJO wants to get some values from ServletContext , I assume that POJO is loaded as part of some servlet call in webapp class loader. This would mean POJO executing inside Servlet Container itself. In this case why would you say ServletContext outside the Servlet Container.
2) As per Bear's reply passing the values and not the ServletContext to the POJO would be a good design with regards to coupling between the POJO and Servlet APIs. This would enable re-use of POJO in some other framework.
Please correct me if I am wrong, especially in #1.

Regds,
Amit
 
reply
    Bookmark Topic Watch Topic
  • New Topic