lisliefor
发贴: 287
|
于 2006-09-15 11:16
首先从这个地方确定是否有问题:JSTL配置,需要将c.tld、fmt.tld、fn.tld放到工程目录下,同时在web.xml中配置(注:我使用的IDE:Eclipse 3.2): <!-- jstl taglib --> <jsp-config> <taglib> <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri> <taglib-location>/WEB-INF/tld/c.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri> <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jsp/jstl/fn</taglib-uri> <taglib-location>/WEB-INF/tld/fn.tld</taglib-location> </taglib> </jsp-config>
<taglib-uri>和<tablib-location>内容根据你在jsp页面使用<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>,和放置tld文件的位置来更改。 使用的时候,需要在相应JSP页面添加<taglib>标签。
然后,我们再看你的例子。首先,我调试过你的例子,没有报错!能够显示:
这里是一个简单的JSTL应用 Customers in the request: guest11 guest22 guest33
现在的时间是:
时间显示不出来,I18N格式标签库,我没用过。不过那个now,你好像没有将它放置到任何隐藏对象中(page、request、session、application)。 而且这句也多余了: <c:set var="customer" scope="session" value="${requestScope.customers}" /> 如果你是为了试图使用<c:set>操作,那么,至少你在下面迭代中,items里的值,应该用${sessionScope.customers}。因为使用${customers},实际情况是这样的,编译器会依次从page、requset、session、application四个对象各自范畴内寻找。找到匹配, 则拿出来。 这样修改一些,结果可以看到,不知道是否合lz意思: <body bgcolor="#FFFFFF"> <h3>这里是一个简单的JSTL应用</h3> <% java.util.Date date = new java.util.Date(); String now = date.toString(); Collection customers = new ArrayList(); customers.add(new String("guest11")); customers.add(new String("guest22")); customers.add(new String("guest33")); //设置customers为request的属性。 request.setAttribute("customers", customers); request.setAttribute("now",now); %> <h4>Customers in the request:</h4> <c:forEach var="customer" items="${customers}"> <c:out value="${customer}" /> <br> </c:forEach> <br> 现在的时间是:${now } <br>
</body>
|