网站上的JSP会话

网站上的JSP会话,jsp,Jsp,我有一个代号叫 User loggeduser = (User)session.getAttribute("loggedUser"); 我对这段代码的用法感到困惑。有人能解释一下这个代码的用法吗?为什么以及如何在其他页面上使用 JSP会话对象用于将一个参数从一个JSP页面发送到另一个JSP页面 假设您有一个表单index.html,它只要求用户输入用户名 <html> <body> <form action="welcome.jsp"> <

我有一个代号叫

User loggeduser = (User)session.getAttribute("loggedUser");

我对这段代码的用法感到困惑。有人能解释一下这个代码的用法吗?为什么以及如何在其他页面上使用

JSP会话对象用于将一个参数从一个JSP页面发送到另一个JSP页面

假设您有一个表单index.html,它只要求用户输入用户名

<html>  
<body>  
<form action="welcome.jsp">  
<input type="text" name="uname">  
<input type="submit" value="go"><br/>  
</form>  
</body>  
</html> 


用户单击提交按钮后,将加载welcome.jsp页面

<html>  
<body>  
<%   

String name=request.getParameter("uname");  
out.print("Welcome "+name);  

session.setAttribute("user",name);  

<a href="second.jsp">second jsp page</a>  

%>  
</body>  
</html>  

现在我有另一个页面,想知道登录用户的名字 为此,我可以像这样使用session.getAttribute

<html>  
<body>  
<%   

String name=(String)session.getAttribute("user");  
out.print("Hello "+name);  

%>  
</body>  
</html>