码迷,mamicode.com
首页 > 其他好文 > 详细

session保存用户登录

时间:2016-06-28 20:35:57      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

<%@ 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>
<%
session.invalidate();
%>
<form action="yanzheng.jsp" method="post">
用户名:<input type="text" name="yonghu"> 
密码:<input type="password" name="mima">
<input type="submit" value="登录">

</form>
</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>
<%
try{
String yonghu=new String(request.getParameter("yonghu").getBytes("ISO-8859-1"),"UTF-8");
String mima=request.getParameter("mima");


    if(yonghu.equals("小小")&& mima.equals("123"))
    {
        session.setAttribute("yonghu", yonghu);
        response.sendRedirect("zhuye.jsp");
        
    }
    else
    {
        
        out.print("用户名或密码错误,请重新输入");
        response.setHeader("refresh", "3;URL=denglu.jsp");
    }


}
catch(Exception e)
{
out.print("请从登录界面登录");
response.setHeader("refresh", "3;URL=denglu.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=GB2312-80">
<title>Insert title here</title>
</head>
<body>
<%

Object obj=session.getAttribute("yonghu");
if(obj==null)
{
out.print("请先登录");
response.setHeader("refresh","3;URL=denglu.jsp");
}
else
{
    String a=new String(obj.toString());
    out.print("欢迎&nbsp;"+a+"&nbsp;登录"); 
%>
<br>
<a href="denglu.jsp"><input type="button" value="退出登录"></a>
<%
} %> 

</body> </html>

技术分享

技术分享

技术分享

技术分享

session保存用户登录

标签:

原文地址:http://www.cnblogs.com/wenwen123/p/5624719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!