1

长话短说:我把它作为输出

<html><body><c:if test="false">
   strange
</c:if></body></html>

将 JSTL 与嵌入式 Jetty 一起使用时。

长话短说:

我的目录结构:

web-example+
           |_src+
           |     \_main+
           |            \_webapp+
           |                    |_index.jspx
           |                    |_WEB-INF+
           |                              \_web.xml
            \_pom.xml

我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="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="WebExample"
    version="2.5">

</web-app>

我的 index.jspx:

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:parts="urn:jsptagdir:/WEB-INF/tags">

<jsp:directive.page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />

<html><body>
    <c:if test="${'1' == true}">
        strange
    </c:if>
</body></html>

</jsp:root>

最后,我的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>web-example</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.simplericity.jettyconsole</groupId>
            <artifactId>jetty-console-maven-plugin</artifactId>
            <version>1.47</version>
            <executions>
                <execution>
                    <goals>
                        <goal>createconsole</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-http</artifactId>
        <version>8.1.4.v20120524</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-server</artifactId>
        <version>8.1.4.v20120524</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-jsp</artifactId>
        <version>8.1.4.v20120524</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-servlet</artifactId>
        <version>8.1.4.v20120524</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>8.1.4.v20120524</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>
</project>

我认为这是特定于 jetty-console-maven-plugin 的问题,因为当我在 Eclipse 中启动 webapp 时一切正常(使用一个启动 Jetty 的小型 Java 类,我没有在这里包含)。

我查看了其他答案,例如,从无法在嵌入式 Jetty 服务器中加载 JSTL taglibJSTL 未在嵌入式 Jetty 实例上运行的 JSP 页面中解析,从而改变了一些帮助我到目前为止的事情,例如,我更新了jetty-console-maven-plugin 为了没有旧的 servlet 规范代码,我从 /usr/share/java 中删除了 jsp 和 servlet JAR,我更新了 web.xml 和 index.jspx 的 XML 规范,等等但它没有帮助。

有人知道出了什么问题吗?

4

1 回答 1

1

我是 JettyConsole 的创建者,我无法使用您提供的代码示例重现您描述的问题。

我使用您提供的文件的内容重新创建了您的目录结构,运行了干净的 Maven 安装并在生成的 jetty-console 战争上运行了 java -jar。

http://localhost:8080/index.jspx 

按预期呈现,并正确解析了 JSLT 代码。

http://localhost:8080/

呈现 403 禁止,可能是因为 index.jspx 不在您的欢迎文件列表中,并且 Jetty 想要隐藏 JSP 源代码。

我想说这个问题应该改进以重现问题,或者关闭。

于 2013-08-15T09:55:54.717 回答