欢迎文件列表不适用于码头+春天 [英] welcome-file-list not working in jetty + spring

查看:107
本文介绍了欢迎文件列表不适用于码头+春天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring 3.2.4中使用Jetty 8.1.4.以下是我的web.xml文件.我在WEB-INF下有一个index.html文件,我希望在我 http://myapp.com/时点击该页面或简单的 http://myapp.com ,但我的代码是404.如果我 http://myapp.com/index.html 可以正常工作.我不确定我缺少什么.另外,如果在下面的url模式中必须使用/或/*,我会感到困惑,我都尝试过.

I'm using Jetty 8.1.4 with Spring 3.2.4. Following is my web.xml file. I have an index.html file under WEB-INF and I want that page to be hit when I do http://myapp.com/ or simple http://myapp.com but I'm getting 404. If I do http://myapp.com/index.html it works. I'm not sure what I'm missing. Also, I'm bit confused if I must use / or /* in the url-pattern below, I tried both.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    id="DOMAINAPPROVALGUI" version="2.4"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>myapp-ui</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/myapp-servlet.xml</param-value>
    </context-param>

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

    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>myappname</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>myappname</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

推荐答案

Jetty 8 is EOL (End of Life), upgrade to Jetty 9. (The answer here is provided based on how Jetty 9 operates.)

<welcome-file-list>DefaultServlet处理的一部分(根据servlet规范).

The <welcome-file-list> is part of the DefaultServlet handling (per servlet spec).

您在<url-pattern>/*</url-pattern>处声明的myappname有效地阻止了DefaultServlet做任何事情.

Your declaration of myappname at <url-pattern>/*</url-pattern> is effectively preventing the DefaultServlet from doing anything.

您的配置基本上说将所有请求发送到我的DispatcherServlet".

Your configuration has basically said "send all requests to my DispatcherServlet".

这甚至包括静态文件服务,欢迎文件处理,默认处理,错误处理,调度等等.

This even includes static file serving, welcome-file handling, default handling, error handling, dispatching, and much much more.

要选择哪种网址格式,由您决定.

As for what url pattern to choose, that's up to you.

有很多使用Spring的方法,您在/*处的当前配置与在*.do*.dispatch/dispatch/*

There are many ways to use Spring, your current configuration at /* is just as valid as others that have it at *.do or *.dispatch or /dispatch/*

您必须确定最适合您的Web应用的内容,并调整Spring在内部的使用,以满足您的需求(例如,声明RequestMapping的方式)

You have to decide what is best for your webapp, and adjust your internal use of Spring to satisfy your needs (such as how you declare your RequestMapping's)

现在您知道了<welcome-file-list>为何不起作用的原因,您可以进行调整以不使用标准servlet <welcome-file-list>(在Spring内部使用),或者调整分派器servlet url模式以允许servlet容器(码头)来提供您的静态文件并处理您声明的<welcome-file-list>.

Now that you know why <welcome-file-list> isn't working, you can make adjustments to either not use the standard servlet <welcome-file-list> (using something internally in Spring), or adjust your dispatcher servlet url pattern to allow the servlet container (Jetty) to serve your static files and handle your declared <welcome-file-list>.

这篇关于欢迎文件列表不适用于码头+春天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆