SpringBoot2.0 集成jsp(勾选web)

springboot集成jsp

  • (1)springboot jsp页面
    》添加依赖servlet ,jstl ,JSP引擎
    》新建webapp目录(没有该目录不能创建jsp)
    》application.properties或者application.yml配置mvc
    springboot不建议大家使用jsp,而推荐使用 thymeleaf
    大家只能手动添加依赖,并且手动创建webapp目录

pom.xml

  <!-- 添加 servlet 依赖. -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- 添加 JSTL(JSP Standard Tag Library,JSP标准标签库) -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!-- Jasper是tomcat中使用的JSP引擎,运用tomcat-embed-jasper可以将项目与tomcat分开 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

webapp

在这里插入图片描述
在这里插入图片描述

application.properties

spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp

springboot集成jsp测试

  • (1)编写Controller
  • (2)请求转发数据到页面(测试el表达式)
  • (3)运行要使用spring-boot:run
@Controller
public class PersonController {
    
    

    @Autowired
    HttpServletRequest request;
    @RequestMapping(path="/test01",method = {
    
    RequestMethod.GET})
    public String test01(){
    
    
        //name jack
        request.setAttribute("name","jack");
        return "person-list";
    }
}

页面

   ${name}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40711092/article/details/110089010