日期:2014-05-17 浏览次数:20797 次
<select name=productionName id="textfield2" size=1> </select>
public class selectProduct extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection conn=null; Statement stmt=null; ResultSet rs=null; List<String> list = new ArrayList<String>(); String sql = "select product_name from product"; ConnectionFactory newconn = new ConnectionFactory(); conn = newconn.getConnection(); try { stmt = conn.createStatement(); rs = stmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } try { while (rs.next()) { String st1 =rs.getString("product_name"); list.add(st1); } } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("list", list); String URL = "/jsp/ReleaseDepend.jsp"; request.getRequestDispatcher(URL).forward(request, response); } }
<select name=productionName id="textfield2" size=1> <c:forEach items="${list}" var="data"> <option value="${data}">${data}</option> </c:forEach> </select>
------解决方案--------------------
你的结果不是都在request中存好了 直接在页面拿出来循环显示就行了~
------解决方案--------------------
你可以在jsp页面中把存好的list打印出来,如果没有数据显示那就说明你的list里面的值没有放进去。list里面有值你就直接循环赋给select
<%
for(int i=0;i<list.size();++i)
{
%>
option value="<%=list.get(i)%>"><%=list.get(i)