0

I'm using eclipse to develop a Google App Engine application. I am on a login page, but I click login, then it shows "Error 405 HTTP method POST is not supported by this URL"?

Here is my servlet code:

my LgServlet.java:

package com.lan; import java.io.IOException; import javax.servlet.http.*; public class LgServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; @Override public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException { check(req,resp); } @Override public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException { check(req,resp); } public void check(HttpServletRequest req,HttpServletResponse resp) throws IOException { if(req.getAttribute("userID").equals("admin")&&req.getAttribute("userPassword").equals("123456")){ resp.setContentType("text/plain"); resp.getWriter().println("Hello Admin"); } } } 

my web.xml:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>lg</servlet-name> <servlet-class>com.lan.LgServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>lg</servlet-name> <url-pattern>/lg</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 

part of index.jsp:

<form action="lg" method="post"> 

I hope someone can help explain to me why I'm getting this error?

Thanks!

1 Answer 1

1

Try changing

<form action="lg" method="post"> 

to

<form action="/lg" method="post"> 

Nothing else looks out of place. I got this error recently, but it was because i was calling super.doPost() in my doPost call.

HTH

Sign up to request clarification or add additional context in comments.

1 Comment

Old thread/ answer, but having super.doPost(), where 'super' is HttpServlet will cause 405.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.