求助!我错在哪了
index.jsp代码:
<form action="servlet/Validate" method="post">
用户名:<input type="text" name="username"><br>
密 码:<input type="password" name="password"><br>
<input type="submit" value="登陆">
</form>
Validate代码:
request.setCharacterEncoding("utf-8");
String username=request.getParameter("username");
String password=request.getParameter("password");
if("张三".equals(username)&&"123".equals(password)){
request.getRequestDispatcher("/success.jsp").forward(request, response);
}else{
response.sendRedirect("../error.jsp");
}
success.jsp代码:
<h1>用户登陆成功!</h1>
<hr>
<%request.setCharacterEncoding("utf-8"); %>
用户名:<%=request.getParameter("username") %> 密码:<%=request.getParameter("password") %>
error.jsp代码:
<h1>用户名或密码错误</h1>
<hr>
<a href="index.jsp">点击返回登陆界面</a>