为什么无论用户名和密码一样不一样都只能登陆到失败界面呢?
<<login.jsp>>代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="dologin.jsp">
用户名:
<input type = "text" name="name"/>
<br>
密码:
<input type="password"name="pass"/>
<br>
提交:
<input type="submit" value="提交"/>
</form>
</body>
</html>
<<dologin.jsp>>代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%String uname = request.getParameter("name");
String pwd = request.getParameter("pass");
if("admin".equals(uname)&&"admin".equals("pwd")){
request.getRequestDispatcher("login_success.jsp").forward(request, response);
}
else{
session.setAttribute("loginuser"," admin");
response.sendRedirect("login_default.jsp");
}
%>
</body>
</html>
登陆成功界面代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">登录成功</h3>
<p align="center">欢迎你</p>
</body>
</html>
登陆失败代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">登录失败<font color="red"><%=session.getAttribute("loginuser") %></font>请检查用户名和密码</h3>
<p align="center"><a href="login.jsp">返回登录界面</a></p>
</body>
</html>