请问在jsp页面上怎么设置session?(在线结分) 什么意思啊?用session比较容易嘛,<%@ page session="true" %><%session.putValue("cartid",gwcid);%><%=session.getValue("cartid") %> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 只要你不在<%@ page session="false" %>,就自动默认了session的使用 我按2楼的代码写了,但是编译出错Error #: 300 : method putValue(java.lang.String, int) not found in interface javax.servlet.http.HttpSession at line 22 <%session.setAttribute("pk","gwcid");%> 写在.jsp文件里,不要写在.java文件里 <%@ page session="true" %>但jsp中这个值是默认设为true的session是内置对象,直接用的session.putValue()方法已经被淘汰了现在都是用session.setAttribute(); 就像4楼写的那样<%session.setAttribute("pk","gwcid");%> session是隐含对象,在jsp里可以直接使用就相当于servlet里的HttpSession类的对象 <%@ page contentType="text/html; charset=GBK" %><html><head><title>Session参数设置和获取示例</title></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>-------------------------------------------------<%@ page contentType="text/html; charset=GBK" %><html><head><title>Session参数设置和获取示例</title></head><body><center><p>产品的名字是<%=session.getAttribute("product")%></p><p>产品的数量是<%=session.getAttribute("quantity")%></p></center></body></html> ibatis 2中,能配置文件中动态指定字段么? jsp中关于条件标签的应用,我不理解结果为什么是那样的,大家讨论下? web 开发问题: Tomcat 无法显示 http://localhost:8080 对于多模块是共用一个数据库好还是分开好? 怎么不相等 还输出啊 (最基本的问题) DWR与Struts那个更为好用 讨论/求解 有关FireFox缓存控制的问题。 问题特别怪,谁能帮我解释! [求助]关于EL的问题?? 如何去掉字符串中的所有空格? 这种情况一般是如何实现的 class="form1"
session是内置对象,直接用的
session.putValue()方法已经被淘汰了
现在都是用session.setAttribute();
<%session.setAttribute("pk","gwcid");%>
就相当于servlet里的HttpSession类的对象
<html>
<head>
<title>Session参数设置和获取示例</title>
</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>
-------------------------------------------------<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>Session参数设置和获取示例</title>
</head>
<body>
<center>
<p>产品的名字是<%=session.getAttribute("product")%></p>
<p>产品的数量是<%=session.getAttribute("quantity")%></p>
</center>
</body>
</html>