• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP not getting application level attribute properly

 
shashi Bhushan Verma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a servlet to get data from database and store them in Hashmap. Then Set an attribute at application level.
To test i vhave written a test jsp.
I am getting that attribute in another JSP. But here the getAttribute returns null some time and sometime it returns normal Hashmap. The return of this random and unable to find any reason for this.

The Test jsp file is Test.jsp with ollowing code
<%@ page import="java.util.HashMap,com.wfe.exceldb.*"%>
<html>
<head></head>
<body>
<h2>The Hash Map value is</h2>
<br>
<%
HashMap map=(java.util.HashMap)application.getAttribute("LoadedValue");
test t=new test();
if(t.update(map))
out.print("the Attribute is set"+map.toString());
else
out.print("The Attribute is not set");
%>
</body>
</html>


Test.java file


Code i am using in another JSP for getting the attribute

HashMap dbMap=new HashMap();
dbMap=(java.util.HashMap)application.getAttribute("LoadedValue");
usr.setLoadValue(dbMap);

Here the attribute doesnot return Map value always. Many times returns null;

The MAP value will be too large containing 30 thousands key value pair.

Please get error.

My main moto is to to make available the Data form the Database for other apllication part during execution.
Please suggest any way as i need to update the attribute value on daily basis.
[ July 04, 2007: Message edited by: Ben Souther ]
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you setting the data in the application object?

I think it is better to use load the Hashmap in a Singleton class or some static class and use this class from your JSP. Or you could write your custom Tag in the JSP to call the Singleton class so as to get the data of the Hashmap in your JSP.
 
shashi Bhushan Verma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Suggestion
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!