制作登录界面,登录成功后把用户名放在session里,在第3个页面读取session显示用户名
Posted 凌零聆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了制作登录界面,登录成功后把用户名放在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>
以上是关于制作登录界面,登录成功后把用户名放在session里,在第3个页面读取session显示用户名的主要内容,如果未能解决你的问题,请参考以下文章