0

My tomcat logs are not showing any errors and from what I can tell the project is configured correctly as well as tomcat 9.

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <tomcat.version>9.0.0.M4</tomcat.version>
        <main.basedir>${basedir}/../..</main.basedir>
    </properties>

More for tomcat:

<!-- Provided (for embedded war support) -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-el</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-logging-juli</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-websocket</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jsp-api</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

Also the index.jsp page renders but displays a blank page. I am using AngularJS and <ng-view> in the page. This is where I am getting the errors:

enter image description here

This is what is being loaded:

enter image description here

It is just loading some stylesheets and my index page.

I map the pages in the project like so:

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    private static final Logger LOGGER = Logger.getLogger(WebConfig.class);

    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);

        registry
            .addResourceHandler("/javascripts/**")
            .addResourceLocations("/resources/javascripts/");

        registry
            .addResourceHandler("/libs/**")
            .addResourceLocations("/resources/libs/");

        registry
            .addResourceHandler("/stylesheets/img/**")
            .addResourceLocations("/resources/images/");

        registry
            .addResourceHandler("/stylesheets/**")
            .addResourceLocations("/resources/stylesheets/");

        registry
            .addResourceHandler("/images/**")
            .addResourceLocations("/resources/images/");

        registry
            .addResourceHandler("/views/**", "/templates/**")
            .addResourceLocations("/resources/templates/");


    };

application.properties

spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp
spring.mvc.static-path-pattern=/resources/*
server.contextPath=/

map the index.jsp here:

@Controller
public class ApplicationController {

    @RequestMapping(value = {"/**", "*" }, method = RequestMethod.GET)
    public String index() {
        return "index";
    }

}

Once it hits the index.jsp file Angular routes should take over:

app.config(function($routeProvider, $locationProvider){
    $routeProvider.when('/',{
        templateUrl: "/templates/misc/home.tpl.html",
        controller: "HomeController"
    })
    .when('/features/blog',{
        templateUrl: "/templates/features/blog.tpl.html",
        controller: "BlogController"
    })
    .when('/features/blogpost',{
        templateUrl: "/templates/features/blog-post.tpl.html",
        controller: "BlogPostController"
    })
    .when('/features/portfolio',{
        templateUrl: "/templates/features/portfolio.tpl.html",
        controller: "PortfolioController"
    })

index.jsp

<body>

        <ng-include src="'/templates/structure/navigation.tpl.html'"></ng-include>
        This is just a test...
        <ng-view autoscroll="true"></ng-view>

        <ng-include src="'/templates/structure/footer.tpl.html'"></ng-include >

        <!--Scripts-->
        <!--<script src="bower_components/masonry/dist/masonry.pkgd.min.js"></script>-->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="/libs/flexslider/jquery.flexslider.js"></script>
        <script src="/libs/masonry/masonry.pkgd.min.js"></script>
        <script src="/libs/imagesloaded/imagesloaded.pkgd.min.js"></script>
        <script src="/libs/angular/angular.min.js"></script>
        <script src="/libs/angular/angular-route.min.js"></script>
        <script src="/libs/angular/angular-sanitize.min.js"></script>
        <script src="/libs/angular/ui-bootstrap-tpls-0.13.0.min.js"></script>
        <script src="/libs/angular-flexslider/angular-flexslider.js"></script>
        <script src="/libs/angular-backstretch/ng-backstretch.min.js"></script>
        <script src="/libs/angular-parallax/angular-parallax.js"></script>
        <script src="/libs/angular-fitvids/angular-fitvids.js"></script>
        <script src="/libs/angular-masonry/angular-masonry.min.js"></script>
        <script src="/libs/momentjs/moment-with-locales.min.js"></script>
        <script src="/libs/humanize-duration/humanize-duration.js"></script>
        <script src="/libs/angular-timer/angular-timer.min.js"></script>
        <script src="/libs/ng-progress/js/ngprogress.min.js"></script>
        <script src="/libs/angular-gmaps/angular-google-maps.min.js"></script>
        <script src="/libs/lodash/lodash.min.js"></script>
        <script src='//maps.googleapis.com/maps/api/js?sensor=false'></script>
        <script src="/javascripts/app.module.js"></script>
        <script src="/javascripts/app.directives.js"></script>
        <script src="/javascripts/app.routes.js"></script>
        <script src="/javascripts/app.controllers.js"></script>
        <script src="/javascripts/app.service.js"></script>

    </body>
</html>

On the blank page it does render "This is just a test" but I get a 404 error for all my Angular and other dependencies, some of which can be seen on the first picture I posted.

My Directory:

enter image description here

------------------- Update 1------------------

context.xml

!-- The contents of this file will be loaded for each web application -->
<Context>

    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>

--------------------Update 2-------------------

I had to add some JSTL tags and was then able to load the scripts. However now something really odd is happening:

<ng-include src="<c:url value="'/templates/structure/navigation.tpl.html'" />"></ng-include>

        <ng-view autoscroll="true"></ng-view>

        <ng-include src="<c:url value="'/templates/structure/footer.tpl.html'" />" ></ng-include>

All the above are showing 404 errors in the console and it renders a blank page.

Mike3355
  • 11,305
  • 24
  • 96
  • 184
  • What context path have you deployed the war with? – Andy Wilkinson Apr 13 '16 at 18:00
  • @AndyWilkinson please see update 1 – Mike3355 Apr 13 '16 at 18:06
  • That doesn't answer my question. The easiest way to set the context path is via the name of the war copied into the webapps directory. There are other ways though (see http://stackoverflow.com/questions/7276989/howto-set-the-context-path-of-a-web-application-in-tomcat-7-0 for example). – Andy Wilkinson Apr 13 '16 at 18:38
  • The name is personalsite. `personalsite` and I am going to the index page via `localhost:8080/personalsite` – Mike3355 Apr 13 '16 at 18:52

1 Answers1

0

Your URLs in index.jsp are wrong as none of them begins with /personalsite. You need to update your JSP to include the context path in the URL. To avoid hardcoding it, you can use the <c:url> tag.

First, register the tag lib at the top of your JSP:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Then you can use it to get a URL that's relative to the context path, for example:

<script src="<c:url value="/libs/flexslider/jquery.flexslider.js"/>"></script>
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • I added the above and I am am able to load the scripts now. However I get a 404 Error for `" >` and two others. – Mike3355 Apr 14 '16 at 17:35