jsp页面动态展示list-使用<select>和<c:forEach>标签

转自:https://blog.csdn.net/zhugewochuang/article/details/80276466

后台:搜索数据放入list,然后为这个list提供响应的get和set方法

 

[java]  view plain  copy
 
  1. private List<String> l=new ArrayList<String>();  
  2. public List<String> getL() {  
  3.         return l;  
  4.     }  
  5.   
  6.     public void setL(List<String> l) {  
  7.         this.l = l;  
  8.     }     
  9. //给list赋值的方法,增加一个默认值:请选择,这样下拉列表展现出来的数据好看些  
  10. public String configUI(){  
  11.         //查询所有的车险渠道来源以及名称,放到list然后传递到前台-channelnamelist  
  12.         l.add("请选择");  
  13.         l.addAll(Service.getChannelname());  
  14.         return "configUI";  
  15.     }  

前台接受

 

 

[html]  view plain  copy
 
  1. <span style="margin-left:50px;font-size:20px;">  
  2.                     渠道来源:<select id="channelname" name="channelname" cssClass="input4">  
  3.                                 <c:forEach var="value" items="${L}">  
  4.                                 <option value="${value}">  
  5.                                 ${value}  
  6.                                 </option>  
  7.                                 </c:forEach>  
  8.                             </select>  
  9.                     </span>  


 

效果图

 

+20160706+

如果是list中是对象呢?

转自:https://blog.csdn.net/bestcxx/article/details/51727592
给下面代码增分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> <a href="zhuce.jsp">发布新闻</a> <a href="../user01/index.jsp">返回主页</a> </form> <table> <thead> <tr> <th>新闻编号</th> <th>新闻标题</th> <%-- <th>新闻内容</th>--%> <th>新闻类别</th> <th>发布人</th> <th>发布时间</th> <th>状态</th> <th>是否头条</th> <th colspan="4" align="center">操作</th> </tr> </thead> <tbody> <c:forEach items="${newslist}" var="u"> <tr> <td>${u.nid}</td> <td>${u.title}</td> <%-- <td>${u.content}</td>--%> <td>${u.type}</td> <td>${u.userName}</td> <td>${u.pubTime}</td> <td> <c:choose> <c:when test="${u.state==0}"><span style="color: ghostwhite">未审核</span></c:when> <c:when test="${u.state==1}"><span style="color: green">审核通过</span></c:when> <c:otherwise><span style="color: red">未通过</span></c:otherwise> </c:choose> </td> <td> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> </td> <c:choose> <c:when test="${user.rule==1}"> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a> </td> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a> </td> <td> <a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a> </td> <td> <a href="Newsshenhe.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">审核</a> </td> </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a></td> <td><a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a></td> </c:when> <c:otherwise> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> </c:otherwise> </c:choose> </tr> </c:forEach> </table>
最新发布
06-01
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*,edu.nustti.dao.*,edu.nustti.dao.impl.*" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>用户注册</title> </head> <body> <form action="/STU_manager/servlet/UserServlet?action=register" name="f1" method="post"> <table border="0"> <tr> <td>用户名:</td> <td><input type="text" name="userName"></td> </tr> <tr> <td>密 码:</td> <td><input type="password" name="password"></td> </tr> <tr> <td>姓 名:</td> <td><input type="text" name="trueName"></td> </tr> <tr> <td>性 别:</td> <td><input type="radio" checked="checked" name="sex" value="0">男 <input type="radio" name="sex" value="1">女 </td> </tr> <tr> <td>生 日:</td> <td><select name="y"> <c:forEach begin="1990" end="2010" var="y"> <option value="${y}">${y}</option> <!-- EL表达式 --> </c:forEach> </select> <select name="m"> <c:forEach begin="1" end="9" var="m"> <option value="0${m}">${m}</option> </c:forEach> <c:forEach begin="10" end="12" var="m"> <option value="${m}">${m}</option> </c:forEach> </select> <select name="d"> <c:forEach begin="1" end="9" var="d"> <option value="0${d}">${d}</option> </c:forEach> <c:forEach begin="10" end="31" var="d"> <option value="${d}">${d}</option> </c:forEach> </select></td> </tr> <tr> <td>爱 好:</td> <td> <% FavoritesDao dao1 = new FavoritesDaolmp1(); // 创建爱好存储业务模型 List list1 = dao1.getAllFavorates(); request.setAttribute("F", list1); %> <c:forEach var="f" items="${F}"> <!-- JSTL标签,列出多个复选框选项 --> <input type="checkbox" name="favorates" value="${f.id }">${f.favorate} </c:forEach> </td> </tr> <tr> <td>班 级:</td> <td> <% ClassesDao dao2 =(ClassesDao) new ClassesDaoImpl(); // 创建班级存储业务模型 List list2 = dao2.getAllClasses(); request.setAttribute("C", list2); %><select name="classId"> <c:forEach var="c" items="${C}"> <!-- JSTL标签,列出多个下拉列表选项 --> <option value="${c.id}">${c.className}</option> </c:forEach> </select> </td> </tr> <tr> <td>介 绍:</td> <td><textarea rows="10" cols="20" name="introduction"></textarea></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="注册"></td> </tr> </table> </form> </body> </html>检查代码
05-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值