Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

jsp page

This is the jsp page where the drop down list option had been applied to retrieve and add set of values

   <tr>
    <td>&nbsp;</td>
    <td width="25%">Vehicle Type :-</td>
    <td width="25%">
      <select value="${veh_type}" style="width:115px;" name="slct_V_type" id="slct_V_type">         
        <option>Select a Type</option>
        <option value="Wagon">Wagon</option>
        <option value="Truck">Truck</option>
        <option value="Bus">Bus</option>
        <option value="SUV">SUV</option>
        <option value="Sedan">Sedan</option>
        <option value="Minivan">Minivan</option>
        <option value="Luxury">Luxury</option>
        <option value="Hybrid">Hybrid</option>
        <option value="Hatchback">Hatchback</option>
        <option value="Coupe">Coupe</option>
      </select></td>
    <td width="25%">&nbsp;</td>

    </tr>

     <td width="25%"><input style="width:100px;" type="submit" name="bttnsrch" id="bttnsrch" value="Search" /></td>

Servlet

ere is the servlet search button coding which will pass the data to the database

 if(request.getParameter("bttnsrch")!=null)
        {
            int Reg=Integer.parseInt(request.getParameter("Reg_number"));
            ResultSet rs=SQL.CaptureVehicleInfo(Reg);
            while(rs.next())
            {

                String veh_type=rs.getString(1);
                request.setAttribute("veh_type", veh_type);

                String reg_num=rs.getString(2);
                request.setAttribute("reg_num", reg_num);

                String veh_brand=rs.getString(3);
                request.setAttribute("veh_brand", veh_brand);

                String veh_model=rs.getString(4);
                request.setAttribute("veh_model", veh_model);

                String veh_man_year=rs.getString(5);
                request.setAttribute("veh_man_year", veh_man_year);

                String no_of_seat=rs.getString(6);
                request.setAttribute("no_of_seat", no_of_seat);

                String trasm=rs.getString(7);
                request.setAttribute("trasm", trasm);

                String air_con=rs.getString(8);
                request.setAttribute("air_con", air_con);
            }
            request.getRequestDispatcher("Vehicle_Information.jsp").forward(request, response);
            response.sendRedirect("Vehicle_Information.jsp");
        }

DB Connection

This the SQL statement I created to search vehicle information from the database.

     public ResultSet CaptureVehicleInfo(int Register_number)
   {
       ResultSet rs;
       try
       {
           SQL=createConnection();

           PreparedStatement ps;
           String str="SELECT * FROM vehicle_information WHERE Register_number=?";
           ps=SQL.prepareStatement(str);

           ps.setInt(1, Register_number);


            rs=ps.executeQuery();
            return rs;

       }
       catch(Exception e)
       {
           rs=null;
           return rs;
       }
   }
share|improve this question
    
what is your question here ? got any errors? – San Krish Jul 31 '14 at 8:48
    
im unable to retrieve the values within the dropdown list once search button is clicked. – Sadzone Jul 31 '14 at 9:44
    
please explain what happens once you click the button . if errors post your stack traces – San Krish Jul 31 '14 at 9:57
    
i dont get any values in the dropdown list but it only retrieves of other text field values. – Sadzone Jul 31 '14 at 10:24
    
'<td><input type="text" name="Reg_number" size="45" id="Reg_number" value="${reg_num}"/></td>' through this i retrieve values to the text field but not retrieving the values of the drop down list – Sadzone Jul 31 '14 at 10:25

You need to iterate the values inside the select tag. you can easily do it using jstl forEach tag like below,

 <select style="width:115px;" name="slct_V_type" id="slct_V_type">
       <c:forEach var="temp" items="${veh_type}">
            <option value="${temp.name}">${temp.name}</option>                  
        </c:forEach>
  </select>

dont forget to add the taglib for jstl support,

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

I expect ${veh_type} contains list of objects

share|improve this answer
    
Thank you for the answer but ${veh_type} doesn't contains list of objects but it is the value assigned to that particular field in order to retrieve the vehicle type once the search button is being executed. – Sadzone Jul 31 '14 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.