my dog learned polymorphism*
The moose likes Servlets and the fly likes Error getServletContext(): NoSuchMethodError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error getServletContext(): NoSuchMethodError" Watch "Error getServletContext(): NoSuchMethodError" New topic
Author

Error getServletContext(): NoSuchMethodError

Syed Ali
Greenhorn

Joined: Oct 08, 2008
Posts: 29

The following code gives the error

String absolutePath = request.getServletContext().getRealPath(item.getName());



Apr 10, 2013 4:25:39 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet ptiSystems threw exception
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Ljavax/servlet/ServletContext;
at com.pti.systems.managers.ImageManager.getImage(ImageManager.java:320)
at com.pti.systems.controllers.ControllerSaveBean.processBean(ControllerSaveBean.java:98)
at com.pti.systems.controllers.ProcessUrlController.handleRequestInternal(ProcessUrlController.java:73)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)


please help why it says no method error

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Did you perchance copy the servlet API jar into WEB-INF/lib? If so, remove it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vas reddy
Greenhorn

Joined: Jun 11, 2008
Posts: 23
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Ljavax/servlet/ServletContext;

You can not get context from request object. Use getServletConfig to get context (or simply use getServeletContext() method)
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1823
    
    7

vas reddy wrote:java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Ljavax/servlet/ServletContext;

You can not get context from request object. Use getServletConfig to get context (or simply use getServeletContext() method)


You can, actually, since version 3.0 of the Servlet specification (->click).


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
vas reddy
Greenhorn

Joined: Jun 11, 2008
Posts: 23
I am sorry, You are right Jelle Klap. Its possible in 3.0.

Hi Syed Ali, could you check your jar file servlet 3.0 version?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Which likely means that the compile time and run time environments use different level of the Servlets API.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error getServletContext(): NoSuchMethodError