在我的Spring Boot Web应用程序的Maven生成war文件(包含JSP,javascript,CSS,静态内容等)之后,当我在tomcat的webapp文件夹中部署war并尝试运行它时,页面显示但我的JSP标签没有工作时,它们像在我的页面上显示为文本一样,例如$ {home}包含在其中,但由于不是可变内容而显示,而在嵌入式tomcat中,一切正常 pom.xml依赖项:
`<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>`
主班
@SpringBootApplication(scanBasePackages={"com"})
public class SpringBootWebAppplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure (SpringApplicationBuilder builder) {
//System.setProperty("spring.devtools.restart.enabled", "false");
return builder.sources(SpringBootWebAppplication.class);
}
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(SpringBootWebAppplication.class, args);
}
}
控制器类
@GetMapping("/seeds")
public String dinkachicka(Model model) {
try{
String message = txt.getMeString();
String arr[]=txt.getMeStringArray();
model.addAttribute("message", message);
model.addAttribute("first",arr[0]);
model.addAttribute("second",arr[1]);
model.addAttribute("third",arr[2]);
model.addAttribute("fourth",arr[3]);
model.addAttribute("fifth",arr[4]);
}
catch(Exception e){
System.out.println(e.getMessage());
}
return "seeds";
}
index.jsp(启动jsp页面)
<%@page language="java" contentType="text/html" pageEncoding="UTF-8" %>
<!Doctype HTML>
<HTML>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/index.css">
</head>
<body class="back" >
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">SimpleFarming</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="/index">Home</a></li>
<li><a href="${pageContext.request.contextPath}/seeds">Seeds</a></li>
<li><a href="${pageContext.request.contextPath}/requirement">Requirements</a></li>
<li><a href="${pageContext.request.contextPath}/Horticulture">Horticulture</a></li>
<li ><a href="${pageContext.request.contextPath}/organicFarming">Organic Farming</a></li>
<li ><a href="${pageContext.request.contextPath}/aboutMe">About Me</a></li>
</ul>
</div>
</nav>
<div >
<p class="homeText "> ${homeText} </p>
<div class="container ">
<div class="row">
<div class="col-sm-3 " ></div>
<div class="col-sm-6">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active" >
<img src="la.jpg" id="image1" alt="Los Angeles">
<div class="carousel-caption">
<h3 onclick="redirectPlease(0);" id="title1"></h3>
<p onclick="redirectPlease(0);" id="para1"></p>
</div>
</div>
<div class="item">
<img src="" id="image2" alt="Chicago">
<div class="carousel-caption">
<h3 onclick="redirectPlease(1);" id="title2"></h3>
<p onclick="redirectPlease(1);" id="para2"></p>
</div>
</div>
<div class="item">
<img src="ny.jpg" id="image3" alt="New York">
<div class="carousel-caption">
<h3 onclick="redirectPlease(2);" id="title3"></h3>
<p onclick="redirectPlease(2);" id="para3"></p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<div class="col-sm-3" ></div>
</div>
</div>
</div>
<div id="footer">
<div class="container">
<div class="row">
<div class="col-sm-12">
This is your footer!
</div>
</div>
</div>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="js/index.js"></script>
</body>
</HTML>
我知道Spring Boot不是制作Web应用程序的正确选择,但现在还是犯错了。请提出任何建议,为什么外部浏览器将我的jsp视为普通HTML而不是 嵌入它正确地进行编译时,我已经设置好了 application.properties文件为
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
server.port=8020