我正在使用eclipse开发Google App Engine应用程序。我在登录页面上,但是我点击登录,然后显示“此URL不支持错误405 HTTP方法POST”?
这是我的servlet代码:
我的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");
}
}
}
我的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>
index.jsp的一部分:
<form action="lg" method="post">
我希望有人可以帮我解释为什么我会收到这个错误?
谢谢!
答案 0 :(得分:1)
尝试更改
<form action="lg" method="post">
到
<form action="/lg" method="post">
没有别的东西看起来不合适。我最近收到了这个错误,但那是因为我在doPost调用中调用了super.doPost()。
HTH