This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JSP and the fly likes Restore the data after the page refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Restore the data after the page refresh" Watch "Restore the data after the page refresh" New topic

Restore the data after the page refresh

Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
I have a JSP page. I have 3 text fields here. I enter some values and submit the form. It talks to the server, does some DB ops and refreshes itself. Here, after the refresh, I want the values that were entered before to be retained with the text fields. so that I can reuse them. I know I can use session for this and I have data stored in session also. But I dont understand how to use it in a jsp page. The session value would be null for the first time the page is loaded and later on it will have values. so, how to have this validation for a text field? I am using some thing like <input type="text" name="endDate" size="8" value="<%=request.getSession().getAttribute("date").getEndDate()%>"> but this is throwing compilation error.
Is this wrong? can this be done in any other way other than what I am doing here?
jyothsna kumari
Ranch Hand

Joined: Jul 21, 2003
Posts: 108
hai padma,
u can use like this.
<input type="text" name="endDate" size="8" value="<%if(session.getAttribute("date")!=null){%><%=session.getAttribute("date")%><%}%>"
hope this helps
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
request.getSession().getAttribute("date") returns an object, you have to typecast it to the object you want

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
This didn't work. when I made these changes and opened up, I got an error. The initial login page itself didn't open. when i remove this statement, it works well. can't track what's up with this :roll:
G Raghavan

Joined: Aug 21, 2000
Posts: 15
The following code worked for me

G Raghavan
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Welcome to the Ranch Raghavan and jyothsna j!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
JSP Forum Bartender
[ October 27, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
sorry for the delayed response.
Thanks Jyotsna, Andres and Raghavan, this works.
I agree. Here's the link:
subject: Restore the data after the page refresh
It's not a secret anymore!