1

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="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

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

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
        <script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>

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

    </head>

    <body>

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

    </body>
</html>

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============= -->

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

     <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet/servlet-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  

    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>webapp.web</param-value>
    </context-param>

    </web-app>

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

4
  • 1
    You forgot the views directory Commented May 5, 2016 at 22:48
  • @Ben Harold - So it'll end up being <script src="js/${contexto}/views/${contexto}-app.js"></script> for example? Commented May 5, 2016 at 23:01
  • My mistake. That directory is on the same level as your JS files. At any rate, you'll want the URL that is included in your script tag to be accessible from your browser. For example: http://localhost:8080/home/js/home/home-app.js should be available from your browser. Commented May 5, 2016 at 23:06
  • Hi, @Ben Harold, you are right... i cannot access the js files from the localhost:8080/web/js/home/... .js Commented May 7, 2016 at 6:30

2 Answers 2

1

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?
Sign up to request clarification or add additional context in comments.

Comments

0

Excuse Me,I advice you Look this demo about Dlobal:

But

  • I think this Global variable exist error when executed,js File not call in .html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.