*
The moose likes JSP and the fly likes Use JavaScript to set form values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Use JavaScript to set form values?" Watch "Use JavaScript to set form values?" New topic
Author

Use JavaScript to set form values?

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Hi, guys:

I have a JSP page with a form of text boxes and dropdowns. Every time
when a user comes to this page, I will try to set form fields with values I
got from database which are put in session. I know we can use struts ActionFomrm to achieve this, but I cannot use Struts for this somehow. Is there any way I can do this using JavaScript or anything else?

regards,
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
A little JSTL should do the trick:

<input name="myTextField" type="text" value="<cut value="${myBean.myProperty}"/>">

or if you're using a JSP 2.0 web container, simply:

<input name="myTextField" type="text" value="${myBean.myProperty}">
[ March 02, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Originally posted by Merrill Higginson:
A little JSTL should do the trick:

<input name="myTextField" type="text" value="<c ut value="${myBean.myProperty}"/>">

or if you're using a JSP 2.0 web container, simply:

<input name="myTextField" type="text" value="${myBean.myProperty}">

[ March 02, 2006: Message edited by: Merrill Higginson ]


Thanks for the reminder. I guess I can just use JSP expressions to populate form values.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Yup, no need to bring in things such as Struts when JSTL and JSP can do it for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use JavaScript to set form values?
 
Similar Threads
No request parameter found in reset method of ActionForm
populated form fields
how to use javascript in struts form?
Putting values back into forms from a database via servlets
document.write() gives script error in IE but not in firefox.