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?
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
Advertisements
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
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.
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 search the selected item in row table using radia button in JSP?
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 retrieve the id value itself from the access database to drop down listbox in jsp
how to add data dynamically from database into a dropdown list in a jsp
how to display data from mysql table in text box using jsp??
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 pass the value of Selected Value of combo box into sql ??
How to Display an alert message when nothing is selected in jspinner in java?
how to get data from list to map with out using a loop?
how to retreive data dynamically from mysql to drop down list
data should not repeat in the drop down list when it is loading dynamically from database
Use of Select Box to show the data from database
data should not repeat in the drop down list when it is loading dynamically from database

Ads