Spring 3中的静态HTML文件问题

Static HTML files issue in spring 3

我全部,

我有一个spring应用程序,用于基于角色的安全性。应用程序运行良好,只是我需要介绍一些静态HTML页面,这些页面也将在同一战争中托管。因此,如果www.myapp.com/abc/work.jsp是我的安全页面,则www.myapp.com/home.htm应该显示静态html页面。我已经合并了HTML文件,但问题是我在www.myapp.com/home.htm上收到404,而www.myapp.com/abc/work.jsp正常工作。

web.xml-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<display-name>guru</display-name>
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/app-security-config.xml</param-value>
    </context-param>

    <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>
    <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>

  <welcome-file-list>
    <welcome-file>/home.htm</welcome-file>
  </welcome-file-list>

我的app-security-config.xml

1
2
3
4
5
6
7
8
9
10
11
12
<http auto-config="false" disable-url-rewriting="false" access-decision-manager-ref="accessDecisionManager"
    entry-point-ref="authenticationProcessingFilterEntryPoint">
    <custom-filter position="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter" />
    <custom-filter position="LOGOUT_FILTER" ref="customLogoutFilter"/>
     
     <intercept-url pattern="/login.htm" filters="none" />
    <intercept-url pattern="/abc/def/**" access="ROLE_USER"/>
    <intercept-url pattern="/**" access="ROLE_ANONYMOUS" />
     
    <session-management session-authentication-strategy-ref="sas"/>  
    <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
    </http>


您好,您应该在调度程序servlet配置中提供静态内容的映射,例如:

1
<mvc:resources mapping="/resources/**" location="/WEB-INF/" />

这样,如果您的静态home.htm内容位于/ WEB-INF /文件夹中,则可以从URL /resources/home.htm进行访问。
这将避免spring拦截并将所有以/ resources开头的路径重定向到控制器,从而保留该路径到静态资源,例如图像,css文件,脚本和html静态页面。