java - Jetty 自动加载 JSP 支持,如何关闭?

标签 java web-applications spring-mvc jetty

当 Jetty 启动时,我在日志中看到以下内容:

 +-WebAppContext@560c3014@560c3014/,file:/C:/MyProjects/ProxyServer/PrepayProxyWebsiteJetty/webapps/root/,webapps/root started
    +-{org.apache.catalina.jsp_classpath=C:\MyProjects\ProxyServer\PrepayProxyWebsiteJetty\webapps\root\WEB-INF\classes, javax.servlet.context.tempdir=C:\Users\davidparks21\AppData\Local\Temp\jetty-0.0.0.0-80-root-_-any-}
    +-{org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher=WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Nov 09 14:38:47 ICT 2010]; parent: Root WebApplicationContext, org.springframework.web.context.support.ServletContextScope=org.springframework.web.context.support.ServletContextScope@3ab6f7f5, org.springframework.web.context.WebApplicationContext.ROOT=Root WebApplicationContext: startup date [Tue Nov 09 14:38:46 ICT 2010]; root of context hierarchy}
    +-SessionHandler@6f7918f0 started
       +-ConstraintSecurityHandler@47f08ed8 started
          +-[]
          +-/={TRACE={RoleInfo,F,C[]}}
          +-ServletHandler@77546dbc started
             +-[/*]/[]==0=>springSecurityFilterChain{}
             +-[/]=>default{resourceCache=resourceCache, maxCacheSize=256000000, dirAllowed=true, gzip=true, maxCachedFileSize=10000000, redirectWelcome=false, acceptRanges=true, welcomeServlets=false, aliases=false, useFileMappedBuffer=true, maxCachedFiles=2048}
             +-[*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp{logVerbosityLevel=DEBUG, fork=false, com.sun.appserv.jsp.classpath=<list_removed>, xpoweredBy=false, scratchdir=C:\Users\davidparks21\AppData\Local\Temp\jetty-0.0.0.0-80-root-_-any-\jsp}
             +-[/]=>dispatcher{}

在我的 webapps web.xml 中,我定义了 springSecurityFilterChain() 和 dispatcher(),但我没有定义 default 和 jsp。

看来JSP支持是默认打开的,这个不应该,我用的是velocity。有没有办法禁用它?

我还看到有一个默认值 dirAllowed=true,这让我很紧张,它不应该在那里吗?

我的 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"
         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" version="2.5">

    <!-- ~~~~~~~~~~~~~~~ SPRING DISPATCHER SERVLET ~~~~~~~~~~~~~~~ -->
    <!-- Allows Spring to handle all web requests -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- ~~~~~~~~~~~~~~~ SPRING SECURITY HOOK ~~~~~~~~~~~~~~~ -->
    <!-- All web requests go through security validation -->
    <filter>
      <filter-name>springSecurityFilterChain</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>springSecurityFilterChain</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- ~~~~~~~~~~~~~~~ BEAN SCOPES FOR WEB ~~~~~~~~~~~~~~~ -->
    <!-- Adds support for scoping beans as: 'request', 'session', and 'global session' -->
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

</web-app>

最佳答案

在 Jetty 7.1.2 中,如果 lib/jsp 中的类在 Jetty 的类路径中,则 JSP 支持将打开,否则将关闭。 start.jar 的 OPTIONS=jsp 参数只是控制它们在类路径中的存在。

禁用 JSP 支持的另一个选项来自 mailing list .本质上,每个部署的 Web 应用程序的默认描述符都包含一个 JSP/Servlet 映射。如果不需要 JSP,则通过将 setDefaultsDescriptor 设置为 null 为给定上下文禁用它。例如:

WebAppContext wac = new WebAppContext();
wac.setDefaultsDescriptor( null ); 

参见 WebAppContext documentation了解详情。

关于java - Jetty 自动加载 JSP 支持,如何关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131505/

相关文章:

java - 如何替换 Java 字符串中的一组标记?

Java 链表问题

java - 无法从静态上下文引用非静态变量 "youngestAge"。任何帮助表示赞赏! :)

java - 创建 ServletContext 资源中定义的名称为 'hibernate4AnnotatedSessionFactory' 的 bean 时出错 [/WEB-INF/dispatcher-servlet.xml] :

java - Jquery Webcam插件使用java将图像上传到服务器

java - 正在创建文件,但 FileConfiguration 未在其中放入文本

javascript - 谷歌分析 javascript web 应用程序

iOS 网络应用程序 : prevent screen dimming/locking

java - 阐明对 JSF 2.0 的理解

spring - 验证表单时出现错误 400 "The request sent was syntactically incorrect"