• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext outside the Servlet Container

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pass the values, not the servlet context, to the POJO.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic