Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can we have a string array in the session.putValue? 1

Status
Not open for further replies.

sreeky

Programmer
Aug 8, 2001
77
US
I have this code which is not functioning any idea why?

String[] rsarray = new String[rssize];
..
..
..
session.putValue("rsarray1", rsarray);
..
..
error while compiling =>

etxrpt_serv.java:249: cannot resolve symbol
symbol : variable rsarray
location: class xxx.yyy.zzz.test
session.putValue("rsarray1", rsarray);
^
etxrpt_serv.java:249: warning: putValue(java.lang.String,java.lang.Object) in javax.servlet.http.HttpSession has been deprecated
session.putValue("rsarray1", rsarray);
^
1 errors
1 warning
 
Since the full code is not available then I can only speculate. Yes, you can definitely put an array into a Session Object. Are you sure that rsarray is in scope by the time you try to add it? Lastly, use setAttribute instead of putValue, as stated putValue has been deprecated.
 
thanx as you said the array was out of scope and i also got rid os putValue()

Thanks a lot!
sreeky
 
since i had some problem using strings ............i am now using vectors.....i have this code which gives me this error...........java.lang.NullPointerException
at the line.........Vector vrs = (Vector) session.getAttribute("vrs"); I am basically trying to use this vector which was created in another servlet and the servlet code is.....

Vector vrs = new Vector();
while ( rs.next()) {
int i=0;
String table_data = rs.getString(1);
out.println(C_RPT_PRTY + &quot;<BR>&quot;);
vrs.add(i, table_data);
i++;
}
session.setAttribute(&quot;vrs&quot;, vrs);

what is the problem??

-sreeky
 
since i had some problem using strings ............i am now using vectors.....i have this code which gives me this error...........java.lang.NullPointerException
at the line.........Vector vrs = (Vector) session.getAttribute(&quot;vrs&quot;); I am basically trying to use this vector which was created in another servlet and the servlet code is.....

Vector vrs = new Vector();
while ( rs.next()) {
int i=0;
String table_data = rs.getString(1);
out.println(table_data + &quot;<BR>&quot;);
vrs.add(i, table_data);
i++;
}
session.setAttribute(&quot;vrs&quot;, vrs);

what is the problem??

-sreeky
 
You are trying to get a Session Attribute that doesn't exist yet. If the attribute does not exist getAttribute returns null and trying to cast null to a Vector is going to throw an exception. Here is a simple piece of code to avoid this error.
Code:
Vector vrs = null;
if (session.getAttribute(&quot;vrs&quot;) != null) {
  vrs = (Vector) session.getAttribute(&quot;vrs&quot;); 
}
Also, in the future it would be better to start a new topic when you post different questions. It is likely to get a better response and adds to the organization of questions so the search feature becomes more useful for returning relevant information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top