在JSP里,用<HTML:SELECT>就能把LIST里的值遍历出来,用<select>+<c:foreach>标签就不行,JSP页面的代码如下,请高手多多指教
<%@ page language="java"%>
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hwhd.entity.Lesson"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
List list = (List)request.getAttribute("list");
if(list != null){
System.out.println("Test is success!");
for(int j = 0;j<list.size();j++){
Lesson l = (Lesson)list.get(j);
System.out.println("term--->"+l.getTerm()+"|||id--->"+l.getId());
}
}else{
System.out.println("error break!");
}
List tt = (List)request.getAttribute("type");
if(tt != null){
for(int i=0;i<tt.size();i++){
Lesson l = (Lesson) tt.get(i);
System.out.println(l.getStudent_type());
}
}%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
  <head>
    <base href="<%=basePath%>">
    <title>timeRual.jsp</title>
    <script id="chromeless" src="<%=path%>/css/script/pz_chromeless_2.1.js"></script>
<link rel="stylesheet" href="<%=path%>/css/9ptext.css" type="text/css">
<link rel="stylesheet" href="<%=path%>/css/Pub.css" type="text/css">
<style type="text/css">
 .qctcCalendar{behavior:url(<%=path%>/css/QctcCalendar.htc);}
 td{font-size:12px}
</style>
  </head>
  <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="2"></td>
  </tr>
</table>
<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td height="18">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="5%"><img src="<%=path%>/images/pub/PubTitleLeft.jpg"></td>
          <td width="90%" valign="bottom" background="<%=path%>/images/pub/PubTitleMiddle.jpg">
            <div align="center" class="bttext">选课时间设置</div></td>
          <td width="3%"><img src="<%=path%>/images/pub/PubTitleRight.jpg"></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td  valign="top" width="90%">
      <html:form method="post" action="/timeRual">
        <table width="98%" border="1" align="center" cellpadding="0" cellspacing="0"  bordercolorlight="#cecfce"  bordercolordark="#ffffff">
          <tr>
            <td class="AddTableText" > 选课学期: </td>
            <td width="48%" class="AddTableSelectText">
<html:select property="term"> <html:options collection="list" labelProperty="term" property="term" /> </html:select>

</td>
            <td width="31%" class="AddTableSelectText">"2005下学期"表示2005年3月--7月</td>
          </tr>
          <tr>
            <td width="21%" class="AddTableText" >选课学生类型:</td>
            <td class="AddTableSelectText"> 
            <!-- <html:select property="student_type">
             <html:option value="请选择">请选择</html:option>
             <html:option value="选修">选修</html:option>
             <html:option value="外校选课">外校选课</html:option>
             <html:option value="高访">高访</html:option>
             <html:option value="高校教师">高校教师</html:option>
             <html:option value="学位班">学位班</html:option>
             <html:option value="硕士">硕士</html:option>
             <html:option value="博士">博士</html:option>
             <html:option value="博士后">博士后</html:option>
            </html:select>     -->   
            <select name="student_type">
              <option value="请选择">请选择</option>
              <c:forEach items="${requestScope.type}" var="myList">
               <option value="${myList.student_type }">${myList.student_type }</option>
              </c:forEach>
            </select>
            
               </td>
            <td class="AddTableSelectText">&nbsp;请选择学生类型</td>
          </tr>
          <tr>
            <td width="21%" class="AddTableText" > 学生选课开始时间:</td>
            <td class="AddTableSelectText"><input class="qctcCalendar" id="RUNTIME" type="text" name="begintime" style="position:relative;font-size: 9pt;font-family: 宋体; border-width: 1px;border:1px solid #60929D;HEIGHT: 18px;  background-color: #F5F0D5;" size="18" />            </td>
            <td class="AddTableSelectText">请填写选课开始日期*</td>
          </tr>
          <tr>
            <td class="AddTableText" >学生选课结束时间:</td>
            <td width="48%" class="AddTableSelectText">
            <td class="AddTableSelectText"><input class="qctcCalendar" id="RUNTIME" type="text" name="endtime" style="position:relative;font-size: 9pt;font-family: 宋体; border-width: 1px;border:1px solid #60929D;HEIGHT: 18px;  background-color: #F5F0D5;" size="18" />  </td>
            <td class="AddTableSelectText">请填写选课开始日期*</td>
          </tr>
            </table>
        </html:form></td>
          </tr>
        </table>
</body>
</html:html>
输出结果:
Test is success!
term--->2005上学期|||id--->10010
term--->2005下学期|||id--->10011
term--->2006上学期|||id--->10012
term--->2006下学期|||id--->10013
term--->2007上学期|||id--->10014
term--->2007下学期|||id--->10015
term--->2008上学期|||id--->10016
term--->2008下学期|||id--->10017
term--->2009上学期|||id--->10018
term--->2009下学期|||id--->10019
term--->2010上学期|||id--->10020
term--->2010下学期|||id--->10021
term--->2011上学期|||id--->10022
term--->2011下学期|||id--->10023
term--->2012上学期|||id--->10024
term--->2012下学期|||id--->10025
term--->2013上学期|||id--->10026
term--->2013下学期|||id--->10027
term--->2014上学期|||id--->10028
term--->2014下学期|||id--->10029
=======================
进修
外校选课
高访
高校教师
学位班
硕士
博士
博士后

解决方案 »

  1.   

    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession();
    int type = Integer.parseInt(request.getParameter("id"));
    LessonDAO dao = new LessonDAO();
    List list = dao.showSelected();
    List myLesson = dao.showTimeRual(type);
    List studenttype = dao.selectStudentType();
    request.setAttribute("hide_id", type);
    request.setAttribute("type", studenttype);
    request.setAttribute("list", list);
    session.setAttribute("MyTimeRual", myLesson);
    return mapping.findForward("success");
    }这个是ACTION
    下边是STRUTS配置文件里的内容
    <action path="/showSelected" type="org.test.struts.action.ShowSelectedAction">
          <forward name="success" path="/test.jsp" />
        </action>
      

  2.   

    requestScope中你能确定已经有东西传过来了吗?
      

  3.   

    代码好长 
    没有看到你的 “输出结果:"是那里输出的
    先做下面的测试把。request.setAttribute("hide_id", type); 
    //这里先检测一下 studenttype 是否有数据。
    System.out.println(studenttype);

    request.setAttribute("type", studenttype); 
    request.setAttribute("list", list); 
      

  4.   

     <c:forEach items="${requestScope.type}" var="myList"> 
          <option value="${myList.student_type }">${myList.student_type } </option> 
     </c:forEach> 
      我没仔细看你的程序,说的不对的地方请见谅。我理解你的意思是想通过<c:forEach>遍历myList集合中每个元素的student_type属性。但是除非你的requestScope.type是一个集合,否则是不可能能够便利出来的(因为requestScope.type不是一个集合)。
      我觉得你是不是误把items="${requestScope}"写成items="${requestScope.type}" 了? 
      

  5.   

    List studenttype = dao.selectStudentType(); request.setAttribute("type", studenttype); 
    代码写的有点乱,呵呵,type确实是一个集合
      

  6.   

    问题找到了,原来是WEB.XML里边有个标签不识别,在我的程序里没显示,但是到了别人的机器上,不识别的标签下边就带红线了
    改了就好了
    谢谢各位的帮助~~