Using context path for local development with AngularJS and Java

Using the context path when developing is a common practice when developing applications locally that use URLs or access static files within the project. When I first started setting up my angularJS project with my existing spring MVC project, I needed to figure out how to have angularJS javascript files reach paths of URLs for my JSON messages using the context path provided in the request object. Below is code I used to solve the problem. I have a header.jsp file that is included in pages. In this file I create a javscript context path variable that is set by the context path provided by the request object. From there this variable is now available to use in grabbing JSON messages in .js files.

[sourcecode language=”javascript”]

var _contextPath = “${pageContext.request.contextPath}”;

[/sourcecode]

[sourcecode language=”javascript”]

url = _contextPath + ‘/secure/alerts/filterAlertSearch’;

[/sourcecode]

Comments

comments