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

Ads
 

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

Ads









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 make drop down list in JSF & fetch data Item from database
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
remove item from list box using java script - Java Beginners
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.
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
Display JSP selected listbox and checkbox in xml-please help me
pbml in inserting selected item from combobox into mysql - XML
How to get data from DB in to Text box by using Jsp & Ajax
how to display the selected row from the data table in model panel ??
retrive the data from access database to drop down list box in jsp
How to search the selected item in row table using radia button in JSP?
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
code for selected checkbox columns data from database
nested selected tag ihave display selected item
Java JComboBox Get Selected Item Value
displaying data for a single column from Mysql database in the list box in php form
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to add data dynamically from database into a dropdown list in a jsp

Ads