注册 登录
编程论坛 J2EE论坛

【求助】关于session问题

haipeng01 发布于 2010-07-12 16:42, 1149 次点击
求助各位大侠,我想把查询出来的数据经过处理之后放到session中,程序上应该怎样实现,如何把数据放到session中
9 回复
#2
baifenghan2010-07-12 21:09
如果是在使用servlet,那么可以使用HttpServletRequest这个类的方法:
 HttpSession getSession()
          Returns the current session associated with this request, or if the request does not have a session, creates one.
 HttpSession getSession(boolean create)
          Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.

如果是使用JSP,那么有一个内置对象,就是session.
#3
hsh_19872010-07-12 22:08
简单的说:
1、Servlet
HttpSession session = request.getSession();
 session.setAttribute("自定义名字", 需要放到session的数据);

2、Jsp(session是Jsp的一个内置对象,直接使用)
session.setAttribute("自定义名字", 需要放到session的数据);
#4
lampeter1232010-07-13 08:21
简单来说就是得到Session对象后,用setAttribute()方法存放数据,用getAttribute()方法取出数据
#5
panghaichao2010-08-09 11:44
1、Servlet
HttpSession session = request.getSession();
session.setAttribute("自定义名字", 需要放到session的数据);

2、Jsp(session是Jsp的一个内置对象,直接使用)
session.setAttribute("自定义名字", 需要放到session的数据);  

3、取的时候
session.getAttribute("自定义名字");  
#6
sunkaidong2010-08-09 12:42
可以使用bean的。用类做封装。
#7
zheng8402010-08-31 12:45
支持上面的,,
#8
ablikim2010-08-31 14:23
以下是引用panghaichao在2010-8-9 11:44:06的发言:

1、Servlet
HttpSession session = request.getSession();
session.setAttribute("自定义名字", 需要放到session的数据);

2、Jsp(session是Jsp的一个内置对象,直接使用)
session.setAttribute("自定义名字", 需要放到session的数据);  

3、取的时候
session.getAttribute("自定义名字");  
同意这个看法,好比把“自定义的名字”换成你要存的数据就可以了,比如说username,password。
#9
wei00002010-09-15 17:30
很好
1