学习练习 session练习

 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 <form action="lianxi2.jsp" method = "post">
11 <input type = "text" name = "username">
12 <input type = "submit" value = "登录">
13 
14 </form>
15 </body>
16 </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 //接收参数
12 String str = new String(request.getParameter("username").getBytes("ISO-8859-1"),"UTF-8");
13 
14 session.setAttribute("name", str);
15 %>
16 添加了session
17 登录成功
18 </body>
19 </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 str=new String(session.getAttribute("name").toString().getBytes("ISO-8859-1"),"UTF-8");
out.print("用户是"+str);



%>
</body>
</html>

原文地址:https://www.cnblogs.com/zhoudi/p/5622413.html