1

Hello everyone I caught an issue with js files in jsp I have a warning

 <script src="<c:url value="bower_components/jquery/dist/jquery.min.js"/>"></script>
<script src="<c:url value="bower_components/bootstrap/dist/js/bootstrap.min.js"/>"></script>

<script src="<c:url value="bower_components/metisMenu/dist/metisMenu.min.js"/>"></script>

<script src="<c:url value="dist/js/sb-admin-2.js"/>"></script>

My jsp can't access to js files

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

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory -->
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>
<mvc:annotation-driven />

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/bap/bower_components/jquery/dist/jquery.min.js] in DispatcherServlet with name 'appServlet'

can someone tell me what's the problem please, thank you

1
  • 1
    How your structure looks like. If you map the url /resourcs/** to /resources, then it should be under resources. e.g: <script src="<c:url value="resources/dist/js/sb-admin-2.js"/>"></script> Commented Nov 25, 2015 at 1:48

1 Answer 1

1

First of all let us understand <mvc:resources mapping="/resources/**" location="/resources/" />.

Here you are configuring the DispatcherServlet of spring MVC to map all HTTP request that has a pattern /resources/** to the physical directory /resources/. This is done to Put resources like cs, js or images into this folder webapp/resources and serve as the static content to the web-app. Reference: Spring MVC - include JS or CSS files in a JSP page

Now, you can resolve your issue in several ways, one of them is explained below:

  • Create a directory named resources inside WebContent. Move all the static contents inside its respective directory, e.g. Move jquery.min.js to WebContent/resources/bower_components/jquery/dist/jquery.min.js and similarly for others.
  • Append /resources/ to the url. In the JSP pages, access the static content as

<script src="<c:url value="/resources/bower_components/jquery/dist/jquery.min.js"/>"></script>

I hope this helps you, feel free to comment for further assistance!

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

1 Comment

I found the solution I just add <script src="<c:url value="/resources/dist/js/sb-admin-2.js"/>"></script> thank's to yu all

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.