This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes session.getAttribute? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "session.getAttribute?" Watch "session.getAttribute?" New topic
Author

session.getAttribute?

Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
this mite seem very familiar...

i have a jsp page that submits some data

<form method="GET" action="submit.jsp">
<INPUT name="firstname" type="text" id="firstname" size="50" maxlength="60" value="" class="mainbodyfont"><%
String firstname = request.getParameter("firstname"); session.setAttribute("firstname",firstname);
%>


and a jsp page
<%= session.getAttribute("firstname") %>



For some reason the jsp page shows "null" value when I submit the form?
Is there any significance to where the scriplet should be in the jsp page i.e. outside the form tags?

Regards
Ali
[ March 12, 2008: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You're dealing with two different requests,
The first draws the page with the form in it.
That request will not have any form parameters so getParameter will return null. Because that returns null it will be adding a null attribute to session.

If you put this:

in 'submit.jsp' then the parameter 'firstname' will be populated.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
I dont think that session has a getParameter function..

I have to use the "session" object.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60783
    
  65

Originally posted by Ashimashi Kabashi:
I have to use the "session" object.
You cannot use the session to retrieve submission parameters. They are present on the request.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
awesome! Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.getAttribute?
 
Similar Threads
Extracting data from a bean
code to call a function in jsp when a checkbox is clicked
code to populate text fields in jsp page
Session in JSP
Simple examples of JSP