aspose file tools*
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 Spring in Action this week in the Spring 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: 61413
    
  67

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?