日期:2014-05-18  浏览次数:20653 次

在select中怎么定位,不用struts标签
<select   name= "district "   size= "1 "   class= "STYLE3 "   value= " <%=request.getAttribute( "district ")%> ">
                <option   name= "district "   value= "0 "> 海淀区 </option>
                <option   name= "district "   value= "1 "> 东城区 </option>
                <option   name= "district "   value= "2 "> 西城区 </option>
                <option   name= "district "   value= "3 "> 宣武区 </option>
                <option   name= "district "   value= "4 "> 崇文区 </option>
                <option   name= "district "   value= "5 "> 朝阳区 </option>
                <option   name= "district "   value= "6 "> 丰台区 </option>
                <option   name= "district "   value= "7 "> 石景山区 </option>
                <option   name= "district "   value= "8 "> 门头沟区 </option>
                <option   name= "district "   value= "9 "> 房山区 </option>
                <option   name= "district "   value= "10 "> 通州区 </option>
                <option   name= "district "   value= "11 "> 大兴区 </option>
                <option   name= "district "   value= "12 "> 顺义区 </option>
                <option   name= "district "   value= "13 "> 平谷区 </option>
                <option   name= "district "   value= "14 "> 怀柔区 </option>
                <option   name= "district "   value= "15 "> 密云县 </option>
                <option   name= "district "   value= "16 "> 密云县 </option>
            </select>

我在action中setAttribute( "district ", "3 ");
其中3是从数据库中得到的
请问在进入该页面时怎么去定位到对应的option

------解决方案--------------------
<option value= "0 " <%=if (request.getAttribute( "district ").equals( "0 ")) out.print( "selected ");%> > 海淀区 </option>

不过每个option都要写,用循环就会方便一点