springboot 访问 jsp文件

♀尐吖头ヾ 提交于 2019-12-16 03:05:51

1.添加依赖(由于springboot本身不支持解析jsp)

        <!-- tomcat的支持.-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

2.在main创建 webapp文件夹 --》WEB-INF文件夹--》jsp文件夹--》jsp文件

jsp文件模板

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>helloword</title>
</head>
<body>
<%
    out.println("Hello World!");
%>

</body>
</html>

3.配置文件添加

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

4.java controller层

 @RequestMapping(value = "/test4")
    public String test4(Person person,Model model) {
        model.addAttribute("person","qwer");
//        System.out.println(person);
//        System.out.println(abc);
        return "demo";
    }

5.页面访问 http://locahost:8080/test4

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!