GeeCON Prague 2014*
The moose likes Servlets and the fly likes ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext" Watch "ServletContext" New topic
Author

ServletContext

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hai,
i am not able to get the instance of the servlet by giving its name in
context.getServlet(name);
i know this method is not capable of loading the required servlet into the memory. but this method returns null even if i send a request to the required servlet externally in the browser as well as sending a request programatically(ie. somehow making it available in the memory).so please help me get out of this problem.
yours
balraj
Sarada Bhasker
Ranch Hand

Joined: Sep 11, 2000
Posts: 94
getServlet() method of ServletContext interface is deprecated in
version 2.1 of servlet API. you should use RequestDispatcher interface instead.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hai sardha,
thanks for your reply.you have said the alternative for req.sendRedirect().so using requestdispatcher i can touch the doGet and doPost methods but my intension is to touch all methods of the servlet instance that is presently available in the memory.
awaiting your reply
yours
balraj
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The reason this call was deprecated is that there is no guarantee that there will be one instance of the named servlet in memory. The servlet container is free to have no instances (if the other servlet has not yet been "init" ed or has already been "destroy"ed) or more than one instance, or even to run the named servlet in another virtual machine completely.
Attempting to access an instance of a servlet in this way is very dangerous and unpredictable, so modern servlet containers are defined to always return null from getServlet().
Can you give us more idea of what you need to achieve? Maybe we can help you find a solution which doesn't involve access to another loaded servlet.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi,
actually i am not trying to get the servlet instance without loading it.i did by externally loading it thro' adminstration tool of javawebserver as well as by putting the request thro' browser.in both cases i falied to get the instance.it returned only null. so again i tried it by loading programatically thro' socket connection and this time also i falied to get the instance.
so combining my experience with your explanation,what i understood is that it is always returning null even if it is available in the memory.
well.the actual intention is that i am creating a servletbean and loads its jar file in the JWS.now my intension is to change its properties from an outside servlet.please help me to work out this one.
yours
balraj
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This is what the servlet context is for.
As your servlet is initialized, you can put your bean into the ServletContext using getServletContext().setAttribute(name, value);
Other servlets will then be able to retrieve the object using getServletContext().getAttribute(name);
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
thanks for your answer and will try this one and i hope now it will work.
thanks a lot,
yours
balraj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext