javascriptjqueryspring-mvcjquery-webcam-plugin

SpringMVC Resources Path Changes When using Href Tag


I have a Spring MVC application it uses jquery.webcam.js this file is located in a js folder in the resources directory on WAR -resources -js,css.. - WEB-INF. Thats the basic structure in the js directory there is a jquery.webcam.js.

When the form that uses jquery.webcam.js and other custom js files is fired its ok it finds all the js files. However on that form i click a button and i am then posted to another page, on this page i have a hyper link that has a url of "getData/${id}.htm". When i click on the hlink i am taken to the controller which has a mapping for this url:

 @RequestMapping(value="getData/{id}.htm", method = RequestMethod.GET) 

In the controller a select is preformed from the database and an object is returned to the previous page (first form - that uses the jquery.webcam.js). When i am returned to that page i am getting in firebug a 404 error for the jquery.webcam.js file.

Upon further inspection the url for the location of my resources has changed from http://localhost:8080/myApp/jquery.webcam.js to http://localhost:8080/myApp/getData/jquery.webcam.js

Why has getData now became part of the resources url and how can this be fixed?


Solution

  • Script files should be loaded like below..

    If your js folder is under resource folder.

    <script src="<%=request.getContextPath()%>/js/jquery.webcam.js"></script>