简体   繁体   English

tomcat7上的servlet eclipse HTTP状态405 - HTTP方法此URL不支持POST

[英]servlet eclipse on tomcat7 HTTP Status 405 - HTTP method POST is not supported by this URL

I'm new to servlet/jsp/portlet tecnology and i'm trying to understand,so as described i'm having an issue with this servlet : 我是servlet / jsp / portlet tecnology的新手,我正在努力理解,所以如上所述我遇到了这个servlet的问题:


package trekking;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Login
 */
public class Login extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * see HttpServlet#HttpServlet()
     */
    public Login() {
    }

    /**
     * @param name 
     * @param pass 
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     * 
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response, String name, String pass) throws ServletException, IOException {
String u,p;
        u=request.getParameter(name);
        p=request.getParameter(pass);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Hello World!</title>");
        out.println("You are "+u+"!");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Hello World!</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

It is called in a html page by this form : 它在这个表单的html页面中调用:

<form action="Login" method="post">
<label for="uname">UserName</label>
<input name="user" id="uname" type="text"></input>
<label for="pwd">Password</label>
<input name="pass" id="pwd" type="password"></input>
<input type="submit" value="invia">
</form>

I'm here if you need anything else. 如果你还需要别的东西,我就在这里。 Thank you. 谢谢。 :D :d

You haven't overriden the doPost method. 您没有覆盖doPost方法。 You've overloaded it. 你已经超负荷了。

protected void doPost(HttpServletRequest request, HttpServletResponse response, String name, String pass) throws ServletException, IOException {

And since nothing is calling your overloaded method, you get the default inherited HttpServlet#doPost() behavior which returns a 405. 由于没有任何东西正在调用您的重载方法,因此您将获得默认的继承HttpServlet#doPost()行为,该行为将返回405。

从doPost方法中删除'name'和'pass'参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP状态405 - 此URL URL servlet不支持HTTP方法POST - HTTP Status 405 - HTTP method POST is not supported by this URL java servlet Tomcat Servlet返回错误405-此URL不支持HTTP方法POST - Tomcat Servlet returns Error 405 - HTTP method POST is not supported by this URL Tomcat:对JSP的Servlet sendRedirect表示:“ HTTP状态405-此URL不支持HTTP方法GET” - Tomcat: Servlet sendRedirect to JSP says: “HTTP Status 405 - HTTP method GET is not supported by this URL” Servlet错误HTTP状态405-此URL不支持HTTP方法GET - Servlet error HTTP Status 405 - HTTP method GET is not supported by this URL Apache Tomcat HTTP状态405-此URL不支持HTTP方法GET - Apache Tomcat HTTP Status 405 - HTTP method GET is not supported by this URL Tomcat 8:HTTP状态405-此URL不支持HTTP方法GET - Tomcat 8: HTTP Status 405 - HTTP method GET is not supported by this URL Tomcat错误HTTP状态405-此URL不支持HTTP方法GET - Tomcat error HTTP Status 405 - HTTP method GET is not supported by this URL 为什么显示为HTTP状态405-此URL不支持HTTP方法POST? - Why it is shown HTTP Status 405 - HTTP method POST is not supported by this URL? HTTP 状态 405:HTTP 方法 POST 不受此 URL 支持 - HTTP Status 405: HTTP method POST is not supported by this URL HTTP状态405-此URL不支持HTTP方法POST,并带有一些警告 - HTTP Status 405 - HTTP method POST is not supported by this URL with some warnings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM