How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?

How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?

I have a jsp page containing a list box and a text box. I am sending an Array List object from a servlet to this jsp page. The listbox gets populated by the data contained in the arraylist. Now, I want to copy the selected item(one at a time) from the list box to the text box. I am unable to do it. Can someone help?

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String dburl = "jdbc:mysql://localhost/sdata"; String user = "dbuser"; String password = "abcd"; ResultSet rs = null; Connection conn=null; PreparedStatement pst = null; ArrayList<User> userlist=new ArrayList<User>();

int x=0; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(db_url, user, password);

String srchtext = request.getParameter("srchtext1"); String radio = request.getParameter("searchradiobox");

if ("teamname".equals(radio)) { pst = conn.prepareStatement("select * from User where team like ?"); pst.setString(1, "%"+srchtext+"%"); } else{ pst = conn.prepareStatement("(select * from User where fname like ?)union (select * from User where lname like ?) "); pst.setString(1, "%"+srchtext+"%"); pst.setString(2, "%"+srchtext+"%"); } rs = pst.executeQuery(); while(rs.next()){ User soluser=new User(); User.setdata(rs.getString("fname"),rs.getString("lname")); userlist.add(x,soluser); x=x+1;
} } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally{ try{ if(rs!=null) { rs.close(); } if(pst!=null) { pst.close(); } if(conn!=null) { conn.close(); } }catch(Exception e){ e.printStackTrace(); } } request.setAttribute("datalist",userlist ); RequestDispatcher rd=request.getRequestDispatcher("expageeditbeta.jsp"); rd.include(request,response); }

The User class is a POJO class. public class User{ String fname; String lname; public void setdata(String a,String b){ fname=a; lname=b; } public String getfname(){ return fname; } public String getlname(){ return lname; } }

The jsp page:
<%! int num=0; String uname; User obj; User objtemp; int limit=0; int index; String nametemp; ArrayList ulisttemp; ArrayList ulist; %>


     User Name
     Team Name
 Search By

View Answers









Related Tutorials/Questions & Answers:
How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?
navigation between panels when item is selected from jcombobox - Swing AWT
Advertisements
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
how to get selected name from combo box
how to get selected name from combo box
remove item from list box using java script - Java Beginners
how to get selected name from combo box
how to get selected name from combo box
how to get selected name from combo box
how to make drop down list in JSF & fetch data Item from database
to update drop down list value when selected from website
to update drop down list value when selected from website
to update drop down list value when selected from website
how to insert the selected item of combobox in mysql - XML
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
pbml in inserting selected item from combobox into mysql - XML
Display JSP selected listbox and checkbox in xml-please help me
retrive the data from access database to drop down list box in jsp
how to display the selected row from the data table in model panel ??
How to get data from DB in to Text box by using Jsp & Ajax
nested selected tag ihave display selected item
How to search the selected item in row table using radia button in JSP?
code for selected checkbox columns data from database
how to insert list box in java script dynamically and elements retrieving from database like oracle
How to send the data selected from drop down menu from html page to sql 2005 database.
displaying data for a single column from Mysql database in the list box in php form
Java JComboBox Get Selected Item Value
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database - Java Beginners
how to insert list box in java script dynamically and elements retrieving from database like oracle
data should not repeat in the drop down list when it is loading dynamically from database
how to enable textfield in j2me netbeans when a choice element is selected?
how to enable textfield in j2me netbeans when a choice element is selected?
data should not repeat in the drop down list when it is loading dynamically from database
data should not repeat in the drop down list when it is loading dynamically from database
how to display data from mysql table in text box using jsp??
how to add data dynamically from database into a dropdown list in a jsp
how to retrieve the id value itself from the access database to drop down listbox in jsp
Use of Select Box to show the data from database
Retrieving Data from Database to fill Combo Box
How to Display an alert message when nothing is selected in jspinner in java?
How to pass the value of Selected Value of combo box into sql ??
how i conditional access the data from database using combo box. - JSP-Servlet
how to get data from list to map with out using a loop?
how to retreive data dynamically from mysql to drop down list
delete an item from database
How to know the selected row from table - JSP-Interview Questions
Populate a combo box using data from a database
code to alert when no checkbox is selected and verify them with orther set
Javascript List Box - JSP-Servlet

Ads