<form name="form1" action="a.jsp" method="post">
          <select name="b">   
<%
ResultSet result=connectSql.executeQuery("select distinct [name] from 表名 where username='"+username+"'"); 
while(result.next()){
%>
            <option value="<%=result.getString("name")%>"><%=result.getString("name")%></option>
<%}%>
          </select>
          <input type="submit" value="跳转"/>
</form>做了这样一个下拉框,option的值从数据库读取,a.jsp有一个同样的下拉框,在这个页面选中一个option,点击跳转提交到a.jsp后,怎样使a.jsp中的select被选中的值是刚刚所提交的?

解决方案 »

  1.   

    在a.jsp中的select标签里面加上一条option标签<option selected=前一个页面选中的选项><%=result.getString("name")%></option> 
      

  2.   

    if.<option <%if(request.getParameter("b").equal("此option值")){%>selected<%}%>></option>
      

  3.   

    <option value="" <%= 参数 == k ? "selected='selected'" : ""%>>
      

  4.   


    <form name="form1" action="a.jsp" method="post"> 
              <select name="b">  
    <% 
    ResultSet result=connectSql.executeQuery("select distinct [name] from 表名 where username='"+username+"'"); 
    while(result.next()){ 
    %> 
                <option value=" <%=result.getString("name")%>"> <%=result.getString("name")%> </option> 
    <%}%> 
              </select> 
              <input type="submit" value="跳转"/> 
    </form>