Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a javascript in a jsp page

Tags:

javascript

jsp

I am new to J2EE and Web development. Here is my issue: I want to include angular.js in the webpage.

Here is the version that works:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <script src="http://code.angularjs.org/1.2.1/angular.min.js"></script>
    <title>Lets Meet Up!</title>
</head>

But I also want to have some local javascript files, and hopefully, I want to import the angularjs in the local directory

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <script src="WEB-INF/lib/angular/angular.js"></script>
    <title>Lets Meet Up!</title>
</head>

The the page is unable to run the javascript.

My stack is Tomcat, Spring MVC, Spring, J2EE I put the angularjs source in AppRoot/WebContents/WEB-INF/lib/angular

Anyone can help? THanks!!

like image 382
BersaKAIN Avatar asked Dec 09 '22 11:12

BersaKAIN


1 Answers

Files in WEB-INF are inaccessible.

Put angular.min.js and all other static assets at the top level of your war file. Or better yet in some nice folder like js/angular/angular.min.js at the top level.

Then do this

<script src="js/angular/angular.min.js"></script>

Depending on your needs you might want to consider serving your assets from a CDN, but that's another story altogether.

like image 186
Vidya Avatar answered Dec 10 '22 23:12

Vidya