Category Archives: servlet

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Problem :

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Solution :

getContextPath() was added with Servlet 2.5, does your version of Jetty supports that ? 

Might also want to check that you do not have some older or duplicate version of j2ee around.

Indicates that Jetty 6.1.x supports Servlet 2.5 , make sure you don’t have a pre-2.5 servlet version around. If this gets loaded before the 2.5 version, the entire classpath sees only Servlet 2.0 API (the 2.5 doesn’t even gets loaded).

so exclude it from the maven pom.xml

Exclusion entry

77 total views, 1 views today

HTTP Status 405 – HTTP method GET is not supported by this URL

Problem :HTTP Status 405 – HTTP method GET is not supported by this URL


Solution :

This is always caused by following two reasons

1) You do not have a valid doGet() method, when you type the servlet’s path in address bar directly, the web container like Tomcat will try to invoke the doGet() method.

public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException{

2) You made a HTTP post request from a HTML form, but you do not

have a doPost() method to handle it. The doGet() cannot handle the “Post” request.


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException{

Example of wrong doGet() and doPost() method
protected void doPost(HttpServletRequest request, HttpServletResponse response, PrintWriter Out){
These two methods get() and post() must have only 2 parameters otherwise it will not be called.

75 total views, no views today