[英]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.