Jsp 文件无法使用 Spring boot mvc 查看



我是使用 jsp 创建的 spring mvc 模式。但是当我调用路由 jsp 包含不显示时

我的项目 JSP 文件路径是

 src/main/resources/META-INF/webapp/WEB-INF.jsp/jsp/Helloworld.jsp

我的索引控制器

@Controller
public class IndexController {
@GetMapping("/helloworld")
String getView(Model model) {
model.addAttribute("msg", "Hello there");
 System.out.printf("test hello world ..................");
 return "Helloworld";
}
}

我的你好世界.jsp

<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<body>
    <h2>${msg}</h2>
</body>
</html>

应用程序属性

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp
welcome.message:helloworld

庞.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.15.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
</dependency>
<dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
</dependency>
<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
</dependency>

当我调用路线

localhost:8000/hellworld 


然后System.out.println消息出现在终端中,但在Web中没有任何显示。
你可以帮我吗?

添加此依赖项:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

然后,通过将以下内容添加到server.port = 8000application.properties中,确保您是正确的端口

最后运行http://localhost:8000/helloworld而不是localhost:8000/hellworld

你的 jsp 页面应该看起来像这样:

<!DOCTYPE html> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello ${msg}!</title>
</head>
<body>
   <h2 >Hello ${msg}!</h2>
</body>
</html>

最新更新