【问题标题】:JSTL tags not working in plain html fileJSTL 标记在纯 html 文件中不起作用
【发布时间】:2010-09-14 23:06:17
【问题描述】:

我有纯 HTML 文件,我想在其中包含一些 JSTL 标记,首先我尝试这是否有效。 但不知何故,JSTL 标签现在在渲染后显示了价值。代码如下:

<html 
xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/"
xmlns:c="http://java.sun.com/jstl/core">
      <body>
       <c:set var="test" value="success" />
       <c:out value="${test}"/>
      </body>
</html>

我的 web.xml 有:

<web-app
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

我还将 jstl-1.2.jar 添加到我的 web-inf/lib 文件夹中。

问题是我在我的 html 页面上没有看到任何内容。我期待看到“成功”。有什么建议吗?

【问题讨论】:

    标签: html jstl


    【解决方案1】:

    类型是 .jsp 吗?如果不是,您如何期望 JSP 引擎知道必须将其编译为 servlet?

    您还必须包含 JSTL 标签库,对吧?

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    

    不能是纯 HTML 文件并期望它作为 JSP 工作。

    【讨论】:

    • 不,它是 .html 类型。原因是我使用该页面的 wicket 框架应该是 html 类型。有什么办法可以在 html 文件中使用 JSTL 标签?
    • 我不明白 JSP 引擎如何知道它需要将 .html 文件编译成 servlet。
    • 看起来你需要使用 Wicket 标签库:javalobby.org/java/forums/t60786.html
    【解决方案2】:

    只需将其包含在您的 web.xml 中即可:

    <servlet-mapping>
            <servlet-name>jsp</servlet-name>
            <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    

    我刚刚在 Tomcat 6.0.37 中测试过

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 2018-03-02
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多