<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'login.jsp' starting page</title>
</head>
<body>
<form name="form" action="dologin.jsp" method="post">
用户名:<input type="text" name="uname"><br>
密码:<input type="password" name="upwd"><br>
<input type="submit" value="登录" >
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'dologin.jsp' starting page</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String uname=request.getParameter("uname");
String upwd=request.getParameter("upwd");
if(uname.equals(upwd)){
session.setAttribute("uname", uname);
request.getRequestDispatcher("main.jsp").forward(request,response);
}else{
request.getRequestDispatcher("no.jsp").forward(request,response);
}
%>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'main.jsp' starting page</title>
</head>
<body>
<h1>登陆成功!</h1>
<%
String uname = (String) session.getAttribute("uname");
if (uname == null)
response.sendRedirect("login.jsp");
%>
<form name="form1" action="loout.jsp" method="post">
<input type="submit" value="退出登录">
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'no.jsp' starting page</title>
</head>
<body>
<h1>登陆失败!!</h1>
<%response.setHeader("refresh", "5;url=login.jsp");%>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'logout.jsp' starting page</title>
</head>
<body>
<%
session.invalidate();
response.setHeader("refresh", "5;url=login.jsp");
%>
</body>
</html>