• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ash sav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for getting list values u can use following syntax.
String sel_values[]=request.getParameterValues("Listname");
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ali Hassaan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is not any restrictions like this
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic