• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacement of deprecated servlet method

 
mohan shetty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic