wood burning stoves 2.0*
The moose likes JSP and the fly likes urgent !!!!how to access contents of list in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "urgent !!!!how to access contents of list in jsp" Watch "urgent !!!!how to access contents of list in jsp" New topic
Author

urgent !!!!how to access contents of list in jsp

Ash sav
Ranch Hand

Joined: Apr 14, 2001
Posts: 55
If I just have simple form having one textfield and list, how can i access the selected element in list?

<html>
<body>
<form name="clientform" method="post" action="database.jsp">

<Table><TR><TD> ID </TD>
<TD><input type = "text" name = "client_id"> </TD> </TR>

<TR><TD> Desired Skills </TD>
<TR> <TD> Skill Set </TD><TD><SELECT NAME="skill">
<OPTION VALUE="">
<OPTION VALUE="os">OS
<OPTION VALUE="rdbms">RDBMS
<OPTION VALUE="gui">GUI
<OPTION VALUE="lang">Languages
</SELECT> </TD></TR>

</Table align = "center">

<Table>
<TR><TD><input type = "radio" name="rowfunction" value="addrow" CHECKED>Add Client</TD>
</TR>
<TR><TD> <INPUT TYPE=Submit name="submit" value="submit"> </TD>
<TD><INPUT TYPE=Reset name="Reset" value="reset"> </TD>
</table>
</form>

</Body>
</Html>
//////////////////////////////////////////////////////////////////////
below is my jsp code. I am not giving complete code just part of it.
//////////////////////////////////////////////////////////////////////
if (rowfunction.equals("addrow")) {
String query = "INSERT INTO client ( client_id, skill) " +
"VALUES ( " +
"'" + request.getParameter("client_id") + "', " +
"'" + request.getParameter("skill"));
try {
statement.executeUpdate(query);

}
catch (SQLException se) {}

}
else { }

I know by applying above code it shows me only client_id value not the selected value in the list.
Thanks in advance,
Ash
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Ash
The code you posted should correctly return the value of the option selected in skill. Keep in ind though that if no option is selected the value will be an empty String "". Is it returning and empty string "" or is it returning null? If it is null then the parameter doesn't exist in the request and you should check all of the spelling involved.


Dave
Ash sav
Ranch Hand

Joined: Apr 14, 2001
Posts: 55
Hi Dave,
thanks for your response. Suppose first time I just want to display selected value in the list and I am not going to consider null value at all. So I did the following chages in my code. But when I hit the submit button I can see that value is actually stored into the myclient table but it's not displaying on the form.
Can u tell me where I am doing wrong?
Thanks,
ASH

if (rowfunction.equals("addrow")) {
String query = "INSERT INTO client ( client_id, skill) " +
"VALUES ( " +
"'" + request.getParameter("client_id") + "', " +
"'" + request.getParameter("skill"));
try {
statement.executeUpdate(query);
}
catch (SQLException se) {}
}
else { }
<%
rs = statement.executeQuery("select * from myclient where client_id = " +
request.getParameter("client_id"));
while(rs.next()){
%>
<Table>
<TR><TD> ID </TD>
<TD><input type = "text" name = "client_id" value=<%= rs.getString("client_id")%>> </TD> </TR>
<TR><TD> Desired Skills </TD>

<TR> <TD> Skill Set </TD><TD><SELECT NAME="skill" size="1" OPTION VALUE="<%=rs.getString("skill")%>">


</SELECT> </TD></TR>
Ali Hassaan
Ranch Hand

Joined: May 16, 2001
Posts: 103
for getting list values u can use following syntax.
String sel_values[]=request.getParameterValues("Listname");
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
rs = statement.executeQuery("select * from myclient where client_id = " +
request.getParameter("client_id"));

You know, if you are using a post method (which I would assume you are), you can read the request body ONLY ONCE, isin't it? So in your stmt above, I would assume you are NOT getting the correct value of the client_id. Since it was already read earlier.
Change your code so you get the client_id from the request, store it in a local variable and use the value in the local variable.
regds.
- madhav


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Ali Hassaan
Ranch Hand

Joined: May 16, 2001
Posts: 103
there is not any restrictions like this
 
Consider Paul's rocket mass heater.
 
subject: urgent !!!!how to access contents of list in jsp