Topic: jsp中如何跨页访问数据

  Print this page

1.jsp中如何跨页访问数据 Copy to clipboard
Posted by: 艾云
Posted on: 2003-06-05 22:39

我有这样一个疑问,
我在第一页中存储了一个对象
在第二,第三页使用
如果在第一页中用request绑定,在第三页就不能访问这个对象了
如果用session绑定,因为无法确定访客会否选择浏览第三页,也就是说无法确定此对象何时应该从session中remove掉。
出于性能的考虑,我只想这个对象的生命周期存在于第二和第三页中,我该如何处理?

2.Re:jsp中如何跨页访问数据 [Re: 艾云] Copy to clipboard
Posted by: 牛老板
Posted on: 2003-06-05 22:47

我是这么想的,可不可以,在第二页中才加上session的选择。。。。如:去3页,,,则:俺才给你session(当然,加上了判断的话,就是不给他session,在2页用request,变量也传过去了,意思是说,只用3页以上的话)....

另:艾云啊,好多人想看你的struts的网站,,,,有个人称是教育网的也访问不了,,,,

3.Re:jsp中如何跨页访问数据 [Re: 艾云] Copy to clipboard
Posted by: floater
Posted on: 2003-06-06 02:22

hidden field in page 1 & 2?

Can't use session because users could use File|New to open a new window, which shares the same session.

4.Re:jsp中如何跨页访问数据 [Re: 艾云] Copy to clipboard
Posted by: archonLing
Posted on: 2003-06-08 14:02

One problem with using hidden variables is that you can't store java object directly as a hidden variable and they are not so secure.

I saw a creative way to better manage session objects. Instead of directly storing data in session object, a named HashMap object, for example, "DataCache", is created as the central storage in session. All storing & removing of cross page data objects are done through "DataCache".

So, in this case, you can store the Page 1 data in DataCache. Then, retrieve them through DataCache on Page 2. If Page 3 is chosen, then the Page 1 data is retrieved from DataCache. Otherwise, you would have the option to clear out all the cached objects at once through clear() or remove them one by one by using remove().

BTW, the reasons for choosing HashMap are :
1. HashMap is a java Collection object, many build-in tools are provided;
2. HashMap is not syncrhonized, so it is faster.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923