JSP教程-JSP session 隐式对象
在 JSP 中,session 是一个类型为 HttpSession 的隐式对象。Java 开发者可以使用这个对象来设置、获取或移除属性,或者获取会话信息。
session 隐式对象的示例
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>
second.jsp
<html>
<body>
<%
String name=(String)session.getAttribute("user");
out.print("Hello "+name);
%>
</body>
</html>