为什么servlet不跳转页面
提交数据时出现:This is class servlet.LoginServlet, using the POST method。不知道哪里出现问题。
提交数据时出现:This is class servlet.LoginServlet, using the POST method。不知道哪里出现问题。
2015-04-20
表单:
<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");
}
}
举报