File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSP
Bookmark "session.getAttribute?" Watch "session.getAttribute?" New topic


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?

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

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

Joined: Jan 10, 2002
Posts: 63838

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] [About Bear] [Books by Bear]
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
awesome! Thanks
I agree. Here's the link:
subject: session.getAttribute?
It's not a secret anymore!