1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%
11 
12 //检查session,取得session信息
13 Object obj = session.getAttribute("username");
14 if(obj != null)
15 {
16     out.print("欢迎登录 "+obj.toString());    
17 }
18 else
19 {
20 out.print("会话超时,请重新登录系统");    
21 //3秒后跳转到用户界面
22 response.setHeader("refresh", "3;URL=Login.jsp");
23 }
24 %>
25 主页面
26 <br>
27 <a href="Login.jsp">退出登录</a>
28 </body>
29 </html>

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 登录页面
11 <br>
12 <%
13 //销毁session
14 session.invalidate();
15 %>
16 
17 <form action="TestPW.jsp" method = "post">
18 用户名:<input type="text"name = "username">
19 密码:<input type="password"name = "password">
20 <input type="submit" value="登录">
21 </form>
22 </body>
23 </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>
<%
//验证用户登录信息是否正确

String un =  request.getParameter("username");
String pw =  request.getParameter("password");

if(un != null && pw != null)
{
    //如果正确  就创建session,并跳转到main.jsp
    if(un.equals("asd") && pw.equals("123"))
    {
        //记录用户信息
        session.setAttribute("username", un);
        
        
        //跳转到系统主页面
        response.sendRedirect("Main.jsp");
        
    }
    else
    {
        //否则就提示登录错误
        out.print("用户名或密码错误");
    }
}
else
{
    out.print("请以正常的方式访问系统");
    }

%>



</body>
</html>

 

 

 

 

 

 

posted on 2016-06-29 11:00  周帝  阅读(5748)  评论(0编辑  收藏  举报