Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  56] [ 7]  / answers: 1 / hits: 101739  / 9 Years ago, wed, november 25, 2015, 12:00:00

I'm trying to run Spring boot app with some HTML5 and JavaScript and I have a problem.



I have project structure like this:



enter



My Spring MVC Controller is calling file offer.html and that works ok.



My offer.html file look like this:



<!DOCTYPE html>
<html lang=en ng-app=coByTu>
<head>
<title>Page</title>
<script type=text/javascript src=../js/lib/angular.js />
<script type=text/javascript src=../js/src/offer.js />
</head>
<body>

</body>
</html>


And when I'm typing my app URL http://localhost:8080/offerView



response from server is:



enter



I have no idea why my app doesn't see this script files, could any one have any idea what i did wrong?


More From » spring-mvc

 Answers
62

Basically all content that needs to be served staticly (such as javascript files) should be placed under the static folder.
https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot


I've thrown together a quick working example to show how it is done:
https://github.com/ericbv/staticContentWithSpringBoot


File structure:
enter


HTML file:


<!DOCTYPE html>
<html lang="en">
<head>
<title>Page</title>
<script type="text/javascript" th:src="@{/js/lib/angular.js}" />
<script type="text/javascript" th:src="@{/js/src/offer.js}" />
</head>
<body>



Using th:src will make sure that the links are context aware


Edit:
added the th:src to make the references context aware


[#64267] Tuesday, November 24, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;