简体   繁体   English

没有从其他jsp上的会话获取哈希表值

[英]not getting hashtable value from session on other jsp

I am setting the value of a hash table in session 我在会话中设置哈希表的值

session.setAttribute("hash",chk); 
Hashtable<Integer,String> navchk = (Hashtable)session.getAttribute("hash");
Enumeration items = navchk.keys();
while(items.hasMoreElements())
{
    out.println(items.nextElement());
}
chk.clear();

at the particular page it is printing the values. 在特定页面上,它正在打印值。 here chk is hashtable. 这里chk是哈希表。

on the other page when i am getting and printing values it is not working. 在另一页上,当我获取和打印值时,它不起作用。 Here is the code of second page.... 这是第二页的代码。

Hashtable<Integer,String> chk1 = (Hashtable<Integer,String>)session.getAttribute("hash");

Enumeration items = chk1.keys();
while(items.hasMoreElements())
{
    out.println(items.nextElement());
}
chk1.clear();

Well for one thing, you are doing, 一方面,您正在做,

chk.clear(); chk.clear();

in your first page. 在您的首页中。 This will clear all your keys from that HashTable . 这将从该HashTable清除所有键。 Keep in mind what you are getting from session, is a reference to the object chk bounded to the key 'hash'. 请记住,您从会话中获得的是对绑定到键“哈希”的对象chk的引用。 If you clear the keys from that object, you will not retrieve any keys in the second page. 如果清除该对象的键,则不会在第二页中检索任何键。

Does that make sense ? 那有意义吗 ? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM