我的tomcat日志没有显示任何错误,我可以告诉项目配置正确以及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>
更多关于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>
index.jsp页面也会呈现,但会显示一个空白页面。我在页面中使用AngularJS和<ng-view>
。这是我收到错误的地方:
这是正在加载的内容:
只是加载了一些样式表和我的索引页。
我像这样在项目中映射页面:
@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=/
在这里映射index.jsp:
@Controller
public class ApplicationController {
@RequestMapping(value = {"/**", "*" }, method = RequestMethod.GET)
public String index() {
return "index";
}
}
一旦命中index.jsp文件,Angular路由应该接管:
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>
在空白页面上,它会渲染&#34;这只是一个测试&#34;但是我的所有Angular和其他依赖项都出现了404错误,其中一些可以在我发布的第一张图片上看到。
我的目录:
-------------------更新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>
--------------------更新2 -------------------
我必须添加一些JSTL标记然后才能加载脚本。然而,现在发生了一件非常奇怪的事情:
<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>
以上所有内容都在控制台中显示404错误,并呈现空白页面。
答案 0 :(得分:0)
index.jsp
中的您的网址错误,因为它们都不以/personalsite
开头。您需要更新JSP以在URL中包含上下文路径。为避免对其进行硬编码,您可以使用<c:url>
标记。
首先,在JSP的顶部注册标记lib:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
然后,您可以使用它来获取相对于上下文路径的URL,例如:
<script src="<c:url value="/libs/flexslider/jquery.flexslider.js"/>"></script>