2012-03-20 95 views
2

我全部,春季静态HTML文件问题3

我有一个弹簧应用程序使用基于角色的安全性。应用程序工作正常,它只是我需要引入一些静态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> 

我的应用程序的安全性-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> 
+0

此链接可能会帮助您http://stackoverflow.com/questions/1234298/can-springmvc-be-configured-process-all-requests-but-exclude-static-content – raddykrish 2012-03-20 04:50:40

+0

是“abc”应用程序中的上下文根目录还是目录? – nickdos 2012-03-20 05:35:26

+0

abc是上下文根,这是生产代码,所以我已经掩盖了它:) – Sachin 2012-03-20 05:36:30

回答

1

嗨,你应该为你的调度servlet配置中的静态内容提供映射,是这样的:

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

这样,如果您的静态home.htm内容位于/ WEB-INF/fold内呃你可以通过url /resources/home.htm找到它。 这将避免春截获和重定向到控制器所有路径开始/资源预留该路径静态资源,如图像,CSS文件,脚本和HTML静态页面