user2098941 user2098941 - 5 months ago 9
HTML Question

Cannot import js files in html

I've been searching for answered questions in here but i couldn't find the suitable one for me. I have an issue when trying to import my javascript files in my html (I'm coding in Eclipse Mars 2.0). I'm using apache tiles for template creation and the project is (trying to be) built in Angularjs. Here i attach some code and screenshots.

My html looks like this, in this first case ${contexto} value is "home"

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="" prefix="tiles"%>

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>

<link rel="stylesheet" href="">

<script src=""></script>
<script src=""></script>

<script src="js/${contexto}/${contexto}-app.js"></script>
<script src="js/${contexto}/${contexto}-service.js"></script>



<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" />


My project is structured this way
project structure

And the error I'm getting when deploying it is this one:
chrome error

Thanks in advance!!!

EDIT I think the problem is related with the servlet configuration... if I comment the servlet config in my web.xml I can access the localhost:8080/web/js/home/home-app.js file and i have the "Hello world" form index.htm but cannot access to localhost:8080/web/home. On the other hand if i discomment them, i cannot access the js files but i can access localhost:8080/web/home. Here is my web.xml if it helps...


<!-- ==============Spring============= -->



<!-- Processes application requests -->




SOLUTION I could solve the issue, defining the resources in the jsp as spring resources instead of the conventional ... tag.


Your script tags are attempting to access a file that does not exist according to your web server. The js/home/home-app.js and js/home/home-service.js portions of the URLs appear to be correct based on the screenshot of your file structure, so the issue is before that.

  • Is this project in the document root or is there a subdirectory where it resides?
  • What happens if you add a slash before js?