|
设置Session的值的页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title> page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center>
<h3> Session参数设置和获取示例 </h3>
<form method= "post " action= "SessionAttrDemo1.jsp ">
<p> 产品标识: <input type= "TextField " name= "product " value= " "> </p>
<p> 产品数量: <input type= "TextField " name= "quantity " value= " "> </p>
<input type= "submit " name= "Submit " value= "设置session参数 ">
<input type= "reset " value= "重写 ">
<a href= "SessionAttrDemo2.jsp "> 显示session的产品标识和数量 </a>
</form>
<%
//取得产品标识
String product = request.getParameter( "product ");
//取得产品数量
String quantity = request.getParameter( "quantity ");
if(product!=null && quantity!=null){
//设置session的产品标识
session.setAttribute( "product ", product);
//设置session的产品数量
session.setAttribute( "quantity ", quantity);
}
%>
</center>
</body>
</html>
取得Session的值的页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>取得session的值</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center>
<p> 产品的名字是 <%=session.getAttribute( "product ")%> </p>
<p> 产品的数量是 <%=session.getAttribute( "quantity ")%> </p>
</center>
</body>
</html> |
|