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

JavaBean <c:foreach> 的问题
public   class   JobBean{
private   int[]   b;

  public   int[]   getB()   {
    return   b;
  }

  public   void   setB(int[]   b)   {
    this.b   =   b;
  }
}
====================
下面的代码如何改用 <c:foreach> 形式?
====================

<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "  

import= "java.sql.*,   com.infoearth.* "  

errorPage= " "   %>
<jsp:useBean   id= "jobInfo "   class= "com.infoearth.JobBean "   scope= "request ">
<jsp:setProperty   name= "jobInfo "   property= "* "/>
</jsp:useBean>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>


<body>
hello
<%
int[]   temp=jobInfo.getB();
for(int   i=0;i <temp.length;i++){
  out.print(i+ "--- "+temp[i]+ " <br> ");

}

%>
</body>
</html>


------解决方案--------------------
<body>
hello
<%
int[] temp=jobInfo.getB();
List list=new ArrayList();
for(int i=0;i <i <temp.length;i++){
list.add(temp[i]);
}
%>
<c:forEach var= "b " items= "${list} " varStatus= "vsc ">
<c:out value= "${b} "> <br>
</c:forEach>
</body>
------解决方案--------------------
<%@ page contentType= "text/html; charset=GBK " %>
<%@ taglib uri= "http://java.sun.com/jsp/jstl/core " prefix= "c " %>
<%
String[] b=request.getParameterValues( "b ");
request.setAttribute( "b ",b);
%>
<c:forEach var= "temp " items= "${requestScope.b} ">
${temp} <br />
</c:forEach>