aspose file tools*
The moose likes Servlets and the fly likes Replacement of deprecated servlet method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Replacement of deprecated servlet method" Watch "Replacement of deprecated servlet method" New topic
Author

Replacement of deprecated servlet method

mohan shetty
Greenhorn

Joined: Oct 26, 2007
Posts: 9
Hi all,
I have a deprecated method from interface ServletRequest.the method is getRealPath(string s).I need to replace this method with a suitable method.can any one suggest me what i need to do.It has been noted in api that we can use ServletContext method.but the arugument passed in the method which i am using is taking a HttpServletRequest which i cant change it.can anyone suggest me what may help me to replace this method.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Have you looked at the API?



getRealPath(java.lang.String path)
Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead.

[ February 05, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42285
    
  64
Well, Mohan mentions that he has seen that method, but that he has an HttpServletRequest to work with, not a ServletContext.

The servlet's init method should store a reference to the ServletConfig object, so that the code can obtain a reference to the ServletContext from it later.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Originally posted by Ulf Dittmer:
The servlet's init method should store a reference to the ServletConfig object, so that the code can obtain a reference to the ServletContext from it later.

As of Servlets 2.4, the servlet context can be obtained directly from the request. No storing necessary.

[ February 05, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ulf Dittmer:
Well, Mohan mentions that he has seen that method, but that he has an HttpServletRequest to work with, not a ServletContext.

The servlet's init method should store a reference to the ServletConfig object, so that the code can obtain a reference to the ServletContext from it later.


Yep,
One count of not reading the original question throughly and completely: Guilty as charged.
mohan shetty
Greenhorn

Joined: Oct 26, 2007
Posts: 9
First of all thank you all for your replies and suggestion.I have already tried with that request.session().getServeltContext().but my page crashes when i run this code with exception NoSuchMethod.this is because my servlet version is 2.2.so what can do further?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42285
    
  64
In that case the servlet needs to be changed along the lines of what I suggested, and the ServletContext passed as a parameter into your method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacement of deprecated servlet method