制作登錄界面,登錄成功后把用戶名放在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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM