提交数据时出现:This is class servlet.LoginServlet, using the POST method。不知道哪里出现问题。
我也是这个问题,跳转不出来
你还应该在doPost()方法里面添加处理内容
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
项目重新部署一下,重启Tomcat
表单:
<form action="servlet/LoginServlet" method="post">
<label>用户名:</label><input type="text" name="username" value=""><br>
<label>密码:</label><input type="password" name="password" value=""><br>
<input type="submit" value="提交">
</form>
LoginServlet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
users u = new users();
String username = request.getParameter("username");
String password = request.getParameter("password");
u.setUsername(username);
u.setPassword(password);
//判断用户名和密码是否正确
if(u.getUsername().equals("admin") && u.getPassword().equals("admin")){
//登录成功,跳转到login_success.jsp
//请求重定向到login_success.jsp
response.sendRedirect(request.getContextPath()+"/login_success.jsp");
}else{
//登录失败,跳转到login_failure.jsp
response.sendRedirect(request.getContextPath()+"/login_failure.jsp");
}
}
代码贴出来啊