Springboot整合Jsp

一. 整合依赖

        <!--jsp maven-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <!--servlet maven-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <!--jstl maven-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>        

二.修改application.properties

server.port=8888
# 页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

#1.1.3版本的(不需要mvc)
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp

三.编写代码 (注意使用@Controller)

@Controller
public class indexController {

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String getIndexJsp(){
        System.out.println("what the matter with jsp ! ");
        return "index";
    }

}

四.编写Jsp (webapp/WEB-INF/jsp/index.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>GOD</title></head>
<body>
helloJsp
<hr>
</body>
</html>

 

posted @ 2018-06-28 16:03  Bockpecehhe  阅读(176)  评论(0)    收藏  举报