This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Restore the data after the page refresh" Watch "Restore the data after the page refresh" New topic
Author

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?
Thanks,
Padma.
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
jyothsna
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
(theObjectYouWant)request.getSession().getAttribute("date")


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
Jyothsna,
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:
Padma.
G Raghavan
Greenhorn

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


G Raghavan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.
Thanks!
bear
JSP Forum Bartender
[ October 27, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [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.
regards,
Padma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restore the data after the page refresh
 
Similar Threads
Holding values after refresh
Struts 1.1 question (Might not be an easy one)
Prepopulating a jsp
servlet or jsp page with prefilled forms
Prepopulating a jsp