Encode issue
I have a Java bean that populates an update form page with database values and everything works except how the values are translated with muttiple words.
For example if a field database value is "The soccer game" it translates it over as "The" and drops anything after the first word. I added the java.net.URLEncoder and it now adds weird characters in the spaces such as "The+soccer+game".Please advise how I can get this to translate over
Here is the part of my ResultSet that I am creating Form values and cant figure out how to sofve this issue?
...
sbuf.append("<form name=main.jsp action=updateFrmPage.jsp method=post>");
while (rs.next())
{
for (int i=1; i <= colNum; i++)
}
sbuf.append("<input type=text name=" + rsmd.getColumnName(i) +" value =" + java.net.URLEncoder.encode(rs.getString(i)) +">");
}
}
sbuf.append("</form>");
.......................
[1295 byte] By [
teser2a] at [2007-11-27 2:24:33]

# 1
Using a form to post the value will automatically escape characters for you.
You don't need to use the java.net.URLEncoder in this instance. You only need it when you are directly constructing a URL with parameters.
The missing thing here is quotes around your attributes.
While HTML will accept things like
<input type=text name=myField value=hello>
The correct form is
<input type="text" name="myField" value="hello">
with quotes around all the values for attributes.
If you don't put quotes around your attributes, html assumes the value ends at the first space it finds. You can use single or double quotes.
So your solution:
// using single quotes
sbuf.append("<input type='text' name='" + rsmd.getColumnName(i) + "' value ='" rs.getString(i) + "'>");
//or double quotes
sbuf.append("<input type=\"text\" name=\"" + rsmd.getColumnName(i) + "\" value =\"" rs.getString(i) + "\">");