qq_散一地寂寞_04176039
2017-10-03 11:14
<<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>
感谢各位,问题解决了。我是在equals后的括号内加了引号。同学们引以为鉴。
JAVA遇见HTML——JSP篇
248278 学习 · 3071 问题
相似问题