【求助】关于session问题
求助各位大侠,我想把查询出来的数据经过处理之后放到session中,程序上应该怎样实现,如何把数据放到session中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. 简单的说:
1、Servlet
HttpSession session = request.getSession();
session.setAttribute("自定义名字", 需要放到session的数据);
2、Jsp(session是Jsp的一个内置对象,直接使用)
session.setAttribute("自定义名字", 需要放到session的数据);
简单来说就是得到Session对象后,用setAttribute()方法存放数据,用getAttribute()方法取出数据 1、Servlet
HttpSession session = request.getSession();
session.setAttribute("自定义名字", 需要放到session的数据);
2、Jsp(session是Jsp的一个内置对象,直接使用)
session.setAttribute("自定义名字", 需要放到session的数据);
3、取的时候
session.getAttribute("自定义名字");
可以使用bean的。用类做封装。 支持上面的,, [quote][b]以下是引用[u]panghaichao[/u]在2010-8-9 11:44:06的发言:[/b]
1、Servlet
HttpSession session = request.getSession();
session.setAttribute("自定义名字", 需要放到session的数据);
2、Jsp(session是Jsp的一个内置对象,直接使用)
session.setAttribute("自定义名字", 需要放到session的数据);
3、取的时候
session.getAttribute("自定义名字");
[/quote]同意这个看法,好比把“自定义的名字”换成你要存的数据就可以了,比如说username,password。 [tk19]很好
页:
[1]