0

I am trying to link images,css and js in jsp but it is not getting parsed in my html (chrome console output : 405 (Method Not Allowed) )

Project Structure

  • src
  • Web Content
    • resources (three folders for css,jsp,and images are here)
    • WEB-INF
      • config (tiles.xml and dispatcher.xml)
      • JSP (all the jsp files are here)

I have done mapping for those resources in web.xml

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
    <url-pattern>*.js</url-pattern>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

Here is resource mapping for the resources

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />

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

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/config-files/tiles.xml</value>
        </list>
    </property>
</bean>

JSP Page

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div id="page-header" class="flag-container">
  <div class="row">
    <div class="col-xs-2" id="header-logo">
        <a href=".">
            <img src="<c:url value="/resources/img/logo.png" />" title="logo" />
        </a>
    </div>
  </div>
</div>
Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
  • Can you see the mapped resource messages successfully when starting your server? Please check the startup logs for any errors. and as Stefan suggested you don't need the resources(css, js) mapping in the web.xml. Simply `/` this handler is enough – Lucky Sep 22 '15 at 12:17
  • same question is answer by me can you refer this : http://stackoverflow.com/questions/31430848/static-resources-with-spring-configuration-class/31431072#31431072 – Manish Prajapati Sep 22 '15 at 12:22
  • Did you also check the server startup log?..and does the resources folder reside on the root of your webapp? – Lucky Sep 22 '15 at 14:15
  • please check the project structure in the question, server startup log is pretty much clean no exception. – Govinda Sakhare Sep 22 '15 at 14:24
  • I'm not telling you to look for exceptions. It will show you something like `INFO: Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'`. Anyway look into this similar post and follow the steps as mentioned there. http://stackoverflow.com/a/16159556/1793718 – Lucky Sep 22 '15 at 14:26

0 Answers0