Spring mvc 瓷砖中的图像/CSS/样式和包含页面中的Spring MVC不起作用

Spring mvc 瓷砖中的图像/CSS/样式和包含页面中的Spring MVC不起作用,spring-mvc,jakarta-ee,model-view-controller,tiles-3,Spring Mvc,Jakarta Ee,Model View Controller,Tiles 3,问题 我正在使用Spring4.1.1和Tiles 3.0.5开发一个应用程序。我可以创建布局。当我直接在layout.jsp中添加图像标记时,我可以看到图像/CSS等,但是当我在不同的jsp中添加相同的图像标记(作为属性添加到布局中)时,所有资源都不起作用。 我可以将控制台中的错误视为 org.springframework.web.servlet.PageNotFound-在名为abc的DispatcherServlet中找不到URI为[/abc/%3Cc:url%20value=%22/r

问题 我正在使用Spring4.1.1和Tiles 3.0.5开发一个应用程序。我可以创建布局。当我直接在layout.jsp中添加图像标记时,我可以看到图像/CSS等,但是当我在不同的jsp中添加相同的图像标记(作为属性添加到布局中)时,所有资源都不起作用。 我可以将控制台中的错误视为 org.springframework.web.servlet.PageNotFound-在名为abc的DispatcherServlet中找不到URI为[/abc/%3Cc:url%20value=%22/resources/images/slides/trial.jpg%22%20/%3E]的HTTP请求的映射

Web.xml

应用程序上下文

瓷砖定义

Layout.jsp

Slider.jsp

如果我在layout.jsp中使用slider.jsp的相同代码,它就可以工作了


我找到了解决办法,但不知道问题出在哪里。通过此链接找到解决方案

我找到了解决方案,但不知道问题出在哪里。通过此链接找到解决方案。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
                    classpath:spring/applicationContext-resource.xml
                    /WEB-INF/spring/applicationContext-base.xml
                    /WEB-INF/spring/applicationContext-dao.xml
        </param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>abc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>abc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  </web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" id="handlerMapping">
        <beans:property name="alwaysUseFullPath" value="true"/>
    </beans:bean>
    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />
    <resources mapping="/styles/**" location="/resources/css" />
    <resources mapping="/images/**" location="/resources/images"/>
    <resources mapping="/js/**" location="/resources/js"/>
    <resources mapping="/fonts/**" location="/resources/fonts"/>

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean id="tilesConfigurer"
     class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>/WEB-INF/tiles-defs/templates.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>

    <beans:bean id="viewResolver"
     class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
    </beans:bean>



    <context:component-scan base-package="com.online.abc" />



</beans:beans>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>
    <definition name="baseLayout" template="/WEB-INF/views/layout/layout.jsp">
        <put-attribute name="title" value="abc" />
        <put-attribute name="header" value="/WEB-INF/views/layout/header.jsp" />
        <put-attribute name="navigation" value="/WEB-INF/views/layout/navigation.jsp" />
        <put-attribute name="slider" value="/WEB-INF/views/layout/slider.jsp"/>
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/views/layout/footer.jsp" />
    </definition>
    <definition extends="baseLayout" name="login">
        <put-attribute name="title" value="SivaLabs : Login" />
        <put-attribute name="navigation" value="" />
        <put-attribute name="body" value="/WEB-INF/views/login.jsp" />
    </definition>
    <definition extends="baseLayout" name="home">
          <put-attribute name="title" value="SivaLabs : Welcome" />
          <put-attribute name="body" value="/WEB-INF/views/home.jsp" />
    </definition>
</tiles-definitions>
<!DOCTYPE html>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title><tiles:insertAttribute name="title" ignore="true" /></title>
        <link rel="stylesheet" type="text/css" href='<c:url value="/resources/css/styles.css" />' />
        <script src='<c:url value="/resources/js/jquery/jquery-2.1.3.min.js" />'> </script>
        <script src='<c:url value="/resources/js/unslider/unslider.js" />'> </script>
    </head>
    <body class="body">
        <div class="headerContent">
            <header class="mainHeader">
                    <tiles:insertAttribute name="header" />
            </header>
        </div>

                    <tiles:insertAttribute name="slider" />


        <%-- <content>
            <tiles:insertAttribute name="body" />
        </content> --%>
        <%-- <footer>
            <tiles:insertAttribute name="footer" />
        </footer> --%>
    </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/javascript">

$(function() {
    $('.banner').unslider();
});
</script>
<body>
    <div class="banner">
        <ul>
            <li><img src='<c:url value="/resources/images/slides/visa.jpg" />'></li>
        </ul>
    </div>
</body>
</html>