2015-01-26 4 views
0

Задача Я разрабатываю приложение с использованием Spring 4.1.1 и Tiles 3.0.5. Я смог создать макет. Когда я добавляю тег Image непосредственно в layout.jsp, я мог видеть изображения/CSS и т. Д., Но когда я добавляю тег Image в другом JSP, который добавляется как «атрибут» к макету, тогда ни один из ресурсы работают. «Я вижу ошибку в консоли как org.springframework.web.servlet.PageNotFound - сопоставления не найдено для HTTP-запроса с URI [/ abc /% 3Cc: url% 20value =% 22/resources/images/slides/trial. JPG% 22% 20 /% 3E] в DispatcherServlet с именем "ABC".Изображения/CSS/Стили в плитках и Spring MVC во вложенных страницах не работают

web.xml

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

Layout.jsp

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

Slider.jsp

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

Если я использую тот же код slider.jsp в layout.jsp, его работает.


enter image description here

+1

Я нашел решение, но понятия не имею, в чем проблема. Нашел решение по этой ссылке. "Http://stackoverflow.com/questions/10340392/javascript-with-spring-mvc-doesnt-work" – Kumar

ответ