【问题标题】:Static HTML files issue in spring 3Spring 3 中的静态 HTML 文件问题
【发布时间】:2012-04-04 14:13:54
【问题描述】:

我都是,

我有一个使用基于角色的安全性的 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 -

<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

<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"/>
    <access-denied-handler error-page="/login.jsp?login_error=true"/> 
     <intercept-url pattern="/login.htm" filters="none" />
    <intercept-url pattern="/abc/def/**" access="ROLE_USER"/>
    <intercept-url pattern="/**" access="ROLE_ANONYMOUS" />
    <anonymous enabled='true'/> 
    <session-management session-authentication-strategy-ref="sas"/>  
    <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
    </http>

【问题讨论】:

  • 此链接可能对您有所帮助stackoverflow.com/questions/1234298/…
  • “abc”是上下文根还是应用中的目录?
  • abc 是上下文根,这是生产代码,所以我已经屏蔽了它:)
  • 我不认为&lt;welcome-file&gt; 正在做你认为它正在做的事情......stackoverflow.com/questions/2511301/… 在这方面可能会有所帮助。它仍然需要映射到 JSP,但我认为这并不能真正帮助您解决主要问题。
  • 是的,欢迎文件无法正常工作,我尝试将其更改为 JSP,但也没有用。

标签: spring spring-mvc spring-security


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-10-21
    • 2015-08-07
    • 2020-08-08
    • 1970-01-01
    • 2011-06-11
    • 2011-11-21
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    相关资源
    最近更新 更多