3

Including floder structure

enter image description hereI am developing a web application in Spring MVC. I have issues loading CSS and JS files in JSP.

I googled for hours and tried all options, but not succeeded. Here is what i did

  1. tried to load as normal web app giving relative path
  2. tried including mvc:resources
  3. tried loading through Resource Servlet even then nothing worked.

All three were tried separately I am wondering what had i missed.

traditional link for #1

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">

No changes done in mvc-config or web.xml

App Config for #2

<mvc:resources mapping="/resources/**" location="/resources/"/>

Web XML for #3

<servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>org.springframework.js.resource.ResouceServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>

enter image description here

2
  • you miss <mvc:annotation-driven /> ? Commented Oct 26, 2016 at 9:01
  • I have this in the xml Commented Oct 28, 2016 at 6:45

1 Answer 1

1

this post helped me to resolve the issue.

How to handle static content in Spring MVC?

But still wondering why my actions were not helpful

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.