使用@PathVariable后,Javascript和css文件在我的jsp页面上出现404错误

时间:2015-04-02 11:12:03

标签: spring jsp spring-mvc web.xml

出于某种原因,当我在我的spring控制器中更改了我的jsp的映射以使用路径变量时,将不加载任何javascript或css文件。我无法在网上找到任何其他的例子。我猜测它在我的web.xml中存在一些映射问题,但我不知道。真的知道。

这是我的控制器代码..

@RequestMapping(value = "common/taskSummary/{taskInstanceId}.do",  method=RequestMethod.GET)
public ModelAndView taskSummary(
        @PathVariable("taskInstanceId") int taskInstanceId) {
    // Get user from Spring security
    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    ModelAndView modelAndView = new ModelAndView("taskSummary");
    modelAndView.addObject("username", user.getUsername());
    return modelAndView;
}

这是我的web.xml ...

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

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml
        /WEB-INF/spring-security.xml  
    </param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>           
<resource-ref>
    <description>ArcFlashMap DB Connection</description>
    <res-ref-name>jdbc/AFM_DB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>    
<servlet>
    <servlet-name>LoadResourcesServlet</servlet-name>
    <servlet-class>ie.premiumpower.services.reports.common.LoadResourcesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.json</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

以下是我在firebugs控制台上遇到的错误......

enter image description here

1 个答案:

答案 0 :(得分:0)

想出来。

我使用href =&#34; ../ css / style.css&#34;来映射我的css和js文件。 但这需要改为href =&#34; ../../ css / style.css&#34;。添加额外的&#34; ../"。