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 can we use servletcontext in a normal java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "can we use servletcontext in a normal java class" Watch "can we use servletcontext in a normal java class" New topic
Author

can we use servletcontext in a normal java class

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
can we use servletcontext in a normal java class?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Do you think you can? If so, why is that? If not, why not?


Ping & DNS - my free Android networking tools app
Goutham Pallipati
Greenhorn

Joined: Aug 13, 2008
Posts: 20
Any Object in fact can be used in any Java Class.

But to obtain the ServletContext Object you need a servlet and further it can be passed to any Class as method parameter and can be used.

Hope this helps. If you are trying to pass it to remote Object remember that it will be Pass by Value also I am not sure if ServletContext is serialized or not.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Goutham Pallipati wrote:
But to obtain the ServletContext Object you need a servlet ...


Not true.
The methods of the listener interfaces provided by the servlet spec all take an argument that contains everything you would need to gain access to the resources in the application.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And as much as possible, your application's classes should not be tied to the servlet spec--it makes testing and refactoring more difficult.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we use servletcontext in a normal java class