ReporterX
ReporterX

Reputation: 1

HTTP method GET is not supported by this URL

i am having trouble with my code as i am accessing the logout servlet from a jsp page's hyperlink.

Jsp page link:

href="/logout"

logout Servlet:

public class logOut extends HttpServlet{

public void doGET(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {

    resp.setContentType("text/html"); 
    System.out.println("log out servlet");
    HttpSession session = req.getSession(false);
    if (session != null) {
        session.invalidate();
    }
    resp.sendRedirect("/signin.jsp");
}
}

but i am having the following error :

HTTP ERROR 405

Problem accessing /logout. Reason:

HTTP method GET is not supported by this URL

please help me.....

Upvotes: 0

Views: 1915

Answers (2)

emboss
emboss

Reputation: 39620

Your method needs to be called

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

in order to be recognized - the uppercase letters make it fail.

Upvotes: 1

Thilo
Thilo

Reputation: 262474

It is called doGet, not doGET.

The @Override annotation would have told you that.

Upvotes: 10

Related Questions