你如何使用JSTL?

时间:2010-03-03 17:43:20

标签: jsf jstl

尝试使用JSTL但存在以下问题:

Index.xhtml页面:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ice="http://www.icesoft.com/icefaces/component" xmlns:jsp="http://java.sun.com/JSP/Page">
<body>
<c:out value="Hello world!"/>
</body></html>

POM:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

OUTPUT SOURCE:

        <html id="document:html" lang="en" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" xmlns:jsp="http://java.sun.com/JSP/Page"><head><meta content="Rendered by ICEFaces D2D" name="icefaces" />
.....
    <c:out value="Hello world!"></c:out>
....</body></html>

正如你可以看到它没有处理c:out而只是将它作为文本打印出来。

2 个答案:

答案 0 :(得分:4)

似乎:

  

解决方案是从jstl名称空间中删除/ jsp:

     

的xmlns:C = “http://java.sun.com/jstl/core”

请参阅此post

答案 1 :(得分:0)

我可以通过添加来解决问题 我的xhtml文件中的xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"

OR

在我的web.xml中声明这一点,并从我的应用程序中复制/ WEB-INF / jsp中的c.tld:

<jsp-config> 
        <taglib> 
               <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri> 
               <taglib-location>/WEB-INF/jsp/c.tld</taglib-location> 
        </taglib> 
</jsp-config>

警告: xmlns:c =“http://java.sun.com/jstl/core”抛出异常,收集在我的h:messages Tag