2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

how to include js library on jsp page?

I have Spring MVC project and on the JSP page I want to include js file from library:

On the JSP page I added the following line:

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

but file is not found:

How to fix this?

userimage

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>
Answer is