File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet Context without servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Context without servlet" Watch "Servlet Context without servlet" New topic
Author

Servlet Context without servlet

Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
Is it possible to get the Servlet or application context for a class(which is not a servlet) running in web container ??
Jasmine kaur
Ranch Hand

Joined: Nov 25, 2003
Posts: 157
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


jasmine kaur
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
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?


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
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
Sri Basavanahally
Ranch Hand

Joined: Oct 07, 2003
Posts: 75
If you have a reference to ServletConfig in your class, you can use it to get the ServletContext.


UP THE IRONS !
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet Context without servlet