Reputation: 446
We have a JSP application developed with Spring-MVC which needs to integrate with AngularJS in some parts of user interaction.
We are running into a problem with urls. JSP application to construct the correct url uses <c:url/>
which prepends the url with root path of a given application. We can of course source AnglularJS in a JSP. But, AngularJS uses internally many relative urls which end up being not found because they lack the root path of the web application. What can be done about it?
Example of AngularJS use of relative urls:
var app = angular.module("app", ['ngDragDrop', "ngRoute", "editor", "popup", "history", "state", "launch"])
.config(function($routeProvider) {
$routeProvider.otherwise({
templateUrl: "res/views/actioner-view.html"
});
});
Upvotes: 0
Views: 194
Reputation: 691695
In your JSP, before loading your scripts, add the following line:
var CONTEXT_PATH = '${pageContext.request.contextPath}';
And everywhere you define a URL in your JavaScript code, use
templateUrl: CONTEXT_PATH + 'res/views/actioner-view.html'
Upvotes: 1