为了账号安全,请及时绑定邮箱和手机立即绑定

为什么无论用户名和密码一样不一样都只能登陆到失败界面呢?

<<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>


正在回答

1 回答

感谢各位,问题解决了。我是在equals后的括号内加了引号。同学们引以为鉴。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么无论用户名和密码一样不一样都只能登陆到失败界面呢?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信