JSP using getParameter to set formfield

M

matt

I have a page that has a section to enter info into a db and list the
people on the same page. When I click on the person, I would like to
reload their info back into the form.

Isn't there a way to set the formfields equal to the resultset that
comes back? I have a link on the name that sends the id of the row in
the db to retrieve their info and allow me to update it.

I'd also like to change the button, but that's not a big deal.

tried this:
Enumeration parameters = request.getParameterNames();
if (parameters.hasMoreElements()){
if( null != idMain && !idMain.equals( "" ) ){
if (action.equals("edit")){
if( null != idMain && !idMain.equals( "" ) ){
Statement stmnt1 = conn.createStatement();
ResultSet editQuery =
stmnt1.executeQuery("select
first_Name,last_Name,belt,sex,age,weight from competitor where
id="+idMain);

while(editQuery.next()){
fName = editQuery.getString("first_Name");
lName = editQuery.getString("last_name");
b = editQuery.getInt("belt");
s = editQuery.getString("sex");
a = editQuery.getInt("age");
w = editQuery.getInt("weight");
}
}
}
}
<tr>
<td>
First name:
</td>
<td>
<input type="Text" name="first_name" value=<%=fName%>>
</td>
</tr>

But if I pick another name, the fName field doesn't change. I think I
have the right intention, just some serious problems in syntax:)

Thanks for any advice!
M@
 
T

Tor Iver Wilhelmsen

matt said:
Isn't there a way to set the formfields equal to the resultset that
comes back? I have a link on the name that sends the id of the row in
the db to retrieve their info and allow me to update it.

A common technique is to use a session-scope bean to represent form
data, with property names equal to the form controls' names. See Sun's
examples for <jsp:useBean> and <jsp:setProperty>.

Then you can just put the data from the ResultSet into that bean, and
refer to the correct property in the value="" attributes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top