今天在书上看到一个jsp页面 的值传递,觉得比网页上的简单,给自己做个笔记,也给需要的朋友借鉴
session.jsp页面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>session</title>
</head>
<body>
<h1>session</h1>
<form action="session1.jsp" method="post">
<input type="text" name="username"/>
<input type="submit" value="输入您的用户名" />
</form>
</body>
</html>
session2.jsp 代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>session1</title>
</head>
<body>
<%
String name=request.getParameter("username");
session.setAttribute("name",name);
%>
用户名是<%=name%>
</body>
</html>
session2.jsp 代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>session2</title>
</head>
<body>
用户名是<%= session.setAttribute("name");%>
</body>
</html>