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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Improper use of string?

Status
Not open for further replies.

phead

MIS
Apr 29, 2004
5
GB
I'm sure this is quite simple, but it defeats me.

I'm using:
String s_param = request.getParameter("PP");

Thats fine, and I can print s_param.

Then
session.setAttribute("S_PARAM_IN", "TEST");

That also fine, and I get get it later and print it, but

session.setAttribute("S_PARAM_IN", s_param);

combining the two fails, it always seems to be null. I assume I'm doing something fundamentally wrong with the string, but being a very new to java I just cannot see it. Anyone care to throw me a bone here?

Cheers

 
Seems OK to me ... how are you retrieving the session attribute ?
 
I'm just using

String passed_param= (String) session.getAttribute("S_PARAM_IN");

to get it, as I said using a quoted string in place of the variable works fine, I assumed this line would be okay based on that.

 
The code you use will defintely work - it must be something in between that is causing the s_param to be null before you set the attribute ...
 
Hmmmm, your correct, moving the get attribute to directly below the other two lines works, it just doesn't work when in another jsp that is being called.

SO
String s_param = request.getParameter("PP");
session.setAttribute("S_PARAM_IN", s_param);
String X= (String) session.getAttribute "S_PARAM_IN");

works only if the last line is in the same jsp file, but changing s_param to a string "TEST" does pass it between the jsp files. Almost as though I'm just passing a refernce to the string, not its string contents, that why I was wondering If im misusing the string?

 
Of course the "TEST" will work ... the reason the s_param won't save on the other JSP is becasue the request parameter is probably not being passed by you (ie in a html <input> tag) - this is the whole point of using session variables ...
 
Sorry I don't understand that are you saying that session parameters are not saved between different jsp files?

 
In the first page, there is a request parameter named "S_PARAM_IN" right, so when you save this in the session, it is not null.

In the second page, you try to also get "S_PARAM_IN" from the request - but there is no such thing because I suspect you have not included it as a <input> tag.

Of course session variables are available between pages - this is the point of them.

These really are basic JSP principals, perhaps you might like to take a reresher course :

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top