Problem I am developing an application using Spring 4.1.1 and Tiles 3.0.5. I could able to create Layout. When I add the Image tag directly in the layout.jsp, I could able to see the Images/CSS etc, but when I add same Image tag in the different JSP which is added as "attribute" to the Layout, then none of the resources is working. "I can see error in console as org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/abc/%3Cc:url%20value=%22/resources/images/slides/trial.jpg%22%20/%3E] in DispatcherServlet with name "abc".
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>
Application Context
<?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>
Tiles Definition
<?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>
If I use same code of slider.jsp in layout.jsp, it is working.
I found solution but have no clue what is the problem. Found the solution from this link JavaScript with Spring MVC doesn't work