為什么無論用戶名和密碼一樣不一樣都只能登陸到失敗界面呢?
<<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>
2017-10-03
感謝各位,問題解決了。我是在equals后的括號內(nèi)加了引號。同學們引以為鑒。