Database value to jsp <select> field as selected

Database value to jsp <select> field as selected

I have a page which wud be used for updation of employee detail.
I am retreiving data from database and showing it on the form.
Problem is this some fields is in <select> and <radio> element how to show those retrieved value in these field.
as i am using this for updation i have to keep other selection values too.
* In code datedisplay is split ted string of date from database.

view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
 <tr>  
                                    <td><label>D.O.B</label></td>  
                                    <td>  
                                        <select name="ebdate">  
                                            <% for(int i=1;i<=31;i++){ if(Integer.parseInt(datedisplay[0])==i){}%>  
                                            <option value="<%=i%>"><%=i%></option>  
                                            <% } %>  
                                        </select>  
                                        <select name="ebmonth">  
                                            <% String[] month={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};   
                                               for(int i=0;i<month.length;i++){  
                                                   if(datedisplay[1].equals(month[i])){  
                                                   }  
                                            %>  
                                            <option value="<%=month[i]%>"><%=month[i]%></option>  
                                            <%} %>  
                                        </select>  
                                        <select name="ebyear">  
                                            <% for(int i=2013;i>=1950;i--){ if(Integer.parseInt(datedisplay[2])==i){}%>  
                                            <option value="<%=i%>"><%=i%></option>  
                                            <%} %>  
                                        </select>  
                                    </td>  
                                </tr>  
                                <tr>  
                                    <td><label>Gender</label></td>   
                                    <td>  
                                        <input type="radio" value="M" size="" name="egender" />Male<br/>  
                                        <input type="radio" value="F" size="" name="egender" />Female  
                                    </td>  
                                </tr>  
                                <tr> 
You can do something like this:

If the currently read value from collection(master list of options) is equal to the database value, then that option should be shown as selected.
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
<select name="x">  
    <%if(condition) %>                 //Condition checking DB value with current collection value  
           <option selected="selected"></option>  
    <%if(!condition) %>              //Reverse condition  
          <option></option>  
</select> 

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright