码迷,mamicode.com
首页 > Web开发 > 详细

jsp 运用 session 登录输出

时间:2016-06-27 17:30:39      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

1、登录页面

<%@ 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="lianxi1.jsp" method="post">
用户名:<input type="text" name="name"><br>
密&nbsp&nbsp&nbsp&nbsp码:<input type="password" name="password"><br>
<input type="submit" value="登录">
</form>
</body>
</html>

 运行并添加数据

技术分享

2、把数据添加到session中

<%@ 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 name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
String password=request.getParameter("password");
session.setAttribute("name", name);
session.setAttribute("pword", password);
%>
添加session成功
</body>
</html>

 技术分享

3、输出session中的内容

<%@ 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 str=session.getAttribute("name").toString();
out.print("name="+str);
String s=session.getAttribute("pword").toString();
out.print("<br>password="+s);
%>
</body>
</html>

 运行结果:

技术分享

 

jsp 运用 session 登录输出

标签:

原文地址:http://www.cnblogs.com/jakeasd/p/5620649.html

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