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
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
remove item from list box using java script - Java Beginners
how to insert the selected item of combobox in mysql - XML
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
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
How to search the selected item in row table using radia button in JSP?
nested selected tag ihave display selected item
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.
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database - Java Beginners
displaying data for a single column from Mysql database in the list box in php form
Java JComboBox Get Selected Item Value
how to insert list box in java script dynamically and elements retrieving from database like oracle
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?
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
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 retrieve the id value itself from the access database to drop down listbox in jsp
data should not repeat in the drop down list when it is loading dynamically from database
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 ??
Use of Select Box to show the data from database
Retrieving Data from Database to fill Combo Box
how to get data from list to map with out using a loop?
how to retreive data dynamically from mysql to drop down list
how i conditional access the data from database using combo box. - JSP-Servlet
How to know the selected row from table - JSP-Interview Questions
delete an item from database
Populate a combo box using data from a database
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
code to alert when no checkbox is selected and verify them with orther set

Ads