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 :
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 :
<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
You haven't overriden the doPost
method. 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.
从doPost方法中删除'name'和'pass'参数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.