A
Anke Barton
I have a database servlet that queries a list of names and it should
then forward this list to a JSP. My servlet uses the setAttribute
method:
visit.java
public void GetProviderList(HttpServletRequest request)
throws SQLException, ClassNotFoundException
{
int i = 0;
String prov_name[] = new String[100];
Statement cmd = con.createStatement();
// Get all providers -> prov_name
String command = "select name from providers ";
ResultSet rset = cmd.executeQuery(command);
while (rset.next()) {
prov_name = rset.getString(1);
i++;
}
// Send array prov_name
request.setAttribute("PROVIDERLIST", prov_name);
rset.close();
cmd.close();
}
Then, the JSP tries to read this string array:
<select name="PROVIDERS" size=1>
<%! String provider_name[] = new String[100]; %>
<% provider_name = request.getParameterValues("PROVIDERLIST"); %>
<%! String fullname = provider_name[0]; %>
<option value=<%= fullname%>><%= fullname %>
</select>
However, the getParameterValue returns a null list. I think that
there is something wrong with my setAttribute function, but I'm new to
Java and can't figure this out.
Thank you for any suggestion.
Anke
then forward this list to a JSP. My servlet uses the setAttribute
method:
visit.java
public void GetProviderList(HttpServletRequest request)
throws SQLException, ClassNotFoundException
{
int i = 0;
String prov_name[] = new String[100];
Statement cmd = con.createStatement();
// Get all providers -> prov_name
String command = "select name from providers ";
ResultSet rset = cmd.executeQuery(command);
while (rset.next()) {
prov_name = rset.getString(1);
i++;
}
// Send array prov_name
request.setAttribute("PROVIDERLIST", prov_name);
rset.close();
cmd.close();
}
Then, the JSP tries to read this string array:
<select name="PROVIDERS" size=1>
<%! String provider_name[] = new String[100]; %>
<% provider_name = request.getParameterValues("PROVIDERLIST"); %>
<%! String fullname = provider_name[0]; %>
<option value=<%= fullname%>><%= fullname %>
</select>
However, the getParameterValue returns a null list. I think that
there is something wrong with my setAttribute function, but I'm new to
Java and can't figure this out.
Thank you for any suggestion.
Anke