This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can we use servletcontext in a normal java class

 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we use servletcontext in a normal java class?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you think you can? If so, why is that? If not, why not?
 
Goutham Pallipati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And as much as possible, your application's classes should not be tied to the servlet spec--it makes testing and refactoring more difficult.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic