-1

I have Spring MVC project and on the JSP page I want to include js file from library: screen 1
(source: pastenow.ru)

On the JSP page I added the following line:

<script src="resources/static/js/kurento-utils.js"></script>

but file is not found:

enter link description here
(source: pastenow.ru)

How to fix this?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • 1
    Aren't you just missing a `/` before `resources`? Should be ` – Daniel B Oct 02 '15 at 07:54
  • It may also work when you add the path for script file from the location of JSP. For example if your jsp is also present in resources folder ignore the resources and use the path as – NightsWatch Oct 02 '15 at 07:58

2 Answers2

0

SpringMVC will serve whatever it finds in resources/static/, so the correct path should be <script src="js/kurento-utils.js"></script>.

You can also check in the tutorials, as we are using the same dependency.

If you want more info about how SpringMVC handles static resources, this other question might also help.

igracia
  • 3,543
  • 1
  • 18
  • 23
0

Use Spring Tag Library to resolve the same, on your JSP page include the tag library and provide the folder path (where your js files are present) as value to <spring:url>, as follows:

JSP Page:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!doctype html>
<html>
<head>
<spring:url value="/js/kurento-utils.js" var="kurentoUtils" />
<script src="${kurentoUtils}"></script>
</head>

In your Spring Configuration file add <mvc:default-servlet-handler /> to load *.js files.

springdispatcher-servlet.xml:

<mvc:default-servlet-handler />

And make sure your have spring-web and spring-webmvc dependencies in your classpath, mentioned below:

pom.xml:

<properties>
        <spring.version>4.1.4.RELEASE</spring.version>
</properties>
<dependencies>
        <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
</dependencies>
Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108