This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.getAttribute?

 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think that session has a getParameter function..

I have to use the "session" object.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome! Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic