How can i get selected value from list.

Thread Solved
Reply

Join Date: Mar 2008
Posts: 4
Reputation: Enjoy is an unknown quantity at this point 
Solved Threads: 0
Enjoy Enjoy is offline Offline
Newbie Poster

How can i get selected value from list.

 
0
  #1
Nov 29th, 2008
Hi all,
I want to retrieve selected item from listbox in a jsp page and send it to a servlet. I am not able to get selected value. Can u please tell me how to get selected value.

In servlet i am trying to get the selected value by using getparameter() function, but its not working.

This is the code i hve given in jsp page:

  1. <%@ page language="java" import="java.util.*" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <title>Unblock Page</title>
  8. </head><br><br>
  9.  
  10. <body background ="bluebg1.jpg" text="DarkBlue">
  11.  
  12. <select name = "urllist" size="1" >
  13. <%Iterator itr;%>
  14. <% List data= (List)request.getAttribute("data");
  15. for (itr=data.iterator(); itr.hasNext(); )
  16. {
  17. String s=itr.next().toString();
  18. %>
  19. <option value = "<%=s%>" > <%=s%> </option>
  20. <%}%>
  21. </select>
  22.  
  23. <form action="./unblock" method="post"><h1 align="center"><input type="submit" value="Unblock" ></h1></form>
  24. <%
  25.  
  26. String urllist = request.getParameter("urllist");
  27. System.out.println("String in jsp"+urllist);
  28. %>
  29.  
  30. </body>
  31. </html>
Last edited by peter_budo; Nov 29th, 2008 at 8:01 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,176
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: How can i get selected value from list.

 
0
  #2
Nov 29th, 2008
Your <select> element (and also any other element eg textfields, checkboxes, etc ) should be inside the <form> </form> tags, if you want your data to get posted (via GET or POST) to the URL specified in the form's action parameter.
From what I see you seem to have no idea how HTML forms work, so I would suggest this tutorial.

And PLEASE use code tags, when you are pasting code. You can read about them here.
This is already your fourth post in roughly 7-8 months and the fact that you still haven't read the rules only shows your ignorance.
Last edited by stephen84s; Nov 29th, 2008 at 2:26 pm.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC