制作登录界面,登录成功后把用户名放在session里,在第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>
<form name="denglu" action="session.jsp" method="post">
登录:<input type="text" name="name">
<br>
爱好:<textarea name="aihao" ></textarea>
<br>
<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>

<%
String name=request.getParameter("name");
session.setAttribute("name", name);
String aihao=request.getParameter("aihao");
session.setAttribute("aihao", aihao);

%>
提交成功
</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>
<%
String name=new String(session.getAttribute("name").toString().getBytes("ISO-8859-1"),"UTF-8");
String aihao=new String(session.getAttribute("aihao").toString().getBytes("ISO-8859-1"),"UTF-8");
out.print("用户:"+name+"<br>");
out.print("爱好:"+aihao+"<br>");

%>
</body>
</html>

posted @ 2016-06-27 22:08  凌零聆  阅读(14744)  评论(0编辑  收藏  举报