首页 > 代码库 > jsp session

jsp session

first.jsp
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<body>
<form method=POST action="next.jsp">
请输入用户名:
<input type=text name="name">
<input type=submit value="http://www.mamicode.com/下一步">
</form>
</body>
</html>
next.jsp
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<body>
<%@ page language="java"%>
<%! String name="";%>
<%
name=request.getParameter("name");
session.putValue("name",name);

response.setHeader("refresh", "1;url=last.jsp");
%>

</body>
</html>

last.jsp
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<body>
<%@ page language="java"%>
<%

request.setCharacterEncoding("UTF-8");
String username=(String) session.getValue("name");
out.print("您好:"+username+"<a href=http://www.mamicode.com/first.jsp>注销");

%>

</body>
</html>

jsp session