2

This is my first question, so, any help will be appreciated. I'm trying angular tutorials, and when I deploy to test the script it cant be found (HTTP 404). i been looking for similar problems, and try solutions like the following: this However, none seems to work. for me is a path problem, because the angular source its pointing to an external source (https) and its working fine, but the local source, not. I'm using eclipse, with tomcat 8 and the default servlet , just only that. i really want to understand why this happen, and thanks for any help. this is my web structure.

web structure

web.xml

<servlet>
 <servlet-name>default</servlet-name>
   <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/js/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

My html:

<!DOCTYPE html>
<html>
  <head>
    <title>AngularJS Controllers</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.5/angular.min.js"></script>
    <script type="text/javascript" src="/js/app.js"></script>
  </head>
  <body>
    <div ng-app="app">
      <h1>Controllers</h1>
       <div ng-controller="MainCtrl">
      <p> {{ message }} </p>
      </div>
    </div>
  </body>
</html>

And my .js

 angular.module('app', []);

angular.module('app').controller('MainCtrl', function ($scope){
      $scope.message = 'hello';
});
David Yee
  • 3,515
  • 25
  • 45
DiegoC
  • 23
  • 1
  • 4

1 Answers1

4

Based on your comments, the most likely thing happening here is your web app runs in a non-ROOT context path. eg. http://localhost:8080/myapp/. If so, the context path should be prepended to /js/app.js, e.g. /myapp/js/app.js. Alternatively, you can reference it from your index page using a relative url. ie. js/app.js (remove the leading slash).

Also, I recommend removing all of the <servlet> and <servlet-mapping> elements shown in the question from web.xml. Tomcat already gives you all the default servlet configs you'll need with no additional effort on your part.

Asaph
  • 159,146
  • 25
  • 197
  • 199
  • hi there, and thanks for your time. i did that, so my web.xml its just the welcome file, and i get this "Failed to load resource: the server responded with a status of 404 (Not found)" when it looks to app.js – DiegoC Feb 11 '16 at 17:29
  • Does using a relative path help? i.e.. `src="js/app.js"`. – Asaph Feb 11 '16 at 17:34
  • thx! that one works. The only i cant get work its telling to tomcat where look for statics resources. but with that i think i can complete the tutorial, thanks! – DiegoC Feb 11 '16 at 17:43
  • I forgot that, sorry!!! – DiegoC Feb 11 '16 at 21:08