This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In File1.jsp you are trying to get a input parameter and trying to set in the session as an attribute. <% String name = request.getParameter( "username" ); session.setAttribute( "theName", name ); %> But from where does the File1.jsp gets the I/P so it gives a null in the output file ie File2.jsp.
Hi Kunal and Siva, Thanks for your response. But I have not set the session attribute to "false" in my code. And I get the input for File1.jsp from "GetName.html" where the text field's name is "username". I am able to retrieve the correct output from File1.jsp but not from File2.jsp. Regards Nandini
Kunal, Thanks. If I pass the parameters in the way you and Siva said, it works. But if I try to get the parameter values from an HTML file, will it not work? Am I making any mistake here? Regards Nandini
Make sure that your html file looks like the above code snippet.It will work. Thanks, Moorthi [ February 16, 2004: Message edited by: Moorthi Ramasamy ] [ February 16, 2004: Message edited by: Moorthi Ramasamy ]
Joined: Jul 04, 2003
Hi Moorthi and Will, I have the following code for the HTML which is similar to yours.
In File1.jsp, the values are retrieved, but when it comes to File2.jsp, it shows 'null' (the session attribute is NOT set to 'false'). Will look into it again. Regards Nandini
Joined: Jan 02, 2004
Originally posted by Nandini Sriram:
In File1.jsp, the values are retrieved, but when it comes to File2.jsp, it shows 'null' (the session attribute is NOT set to 'false'). Will look into it again.
Add the following line in File2.jsp. If you see "true", check your browser whether cookie is enabled or not.
Regardless of "true/false" in the above check, add the following line in the File1.jsp. Everything should be fine.
Joined: Jul 04, 2003
Moorthi, Thanks for your response. I tried including those lines. But the result was the same. However, I tried including "toString()" to request.getAttribute("username").toString() in File1.jsp and I was able to see the correct output "Hello, Nandini" in File2.jsp. Regards Nandini
Nandini, I think the reason might be when you try to use session.getAttribute( "theName" )to display the value. You have to cast it to a String, because seesion.getAttribute returns a Object not a String. Even the toString() inside the object will not return a value for the object, it will only return a reference to it which is null. That's why you get a null value. Try to do this (String)session.getAttribute. It will work. If I am wrong, please let me know. By the way, the default value of session is set to true for JSP page. Regards, Paul [ February 19, 2004: Message edited by: Paul Yen ] [ February 19, 2004: Message edited by: Paul Yen ]