• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restore the data after the page refresh

 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getSession().getAttribute("date") returns an object, you have to typecast it to the object you want
(theObjectYouWant)request.getSession().getAttribute("date")
 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code worked for me
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for the delayed response.
Thanks Jyotsna, Andres and Raghavan, this works.
regards,
Padma.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic