The springboot project created in eclipse is changed to use jsp

1. Create your own springboot project

Configure applicaton.properties configuration file

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

Add the web directory under src. Note that the webapp structure directory is added under src/ main/

Right-click the project and select propeties for project configuration

Apply after clicking apply

Will generate webcontent This folder can be deleted because we are using maven's own configured web or webapp directory

Right-click project properties configuration

There will be a directory at this time

Select him to remove webcontent and add your own web directory

 

Add to

 

Add jsp file

Write the controller

package com.hy.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class HelloController {
	
	@GetMapping("hellopage")
	public ModelAndView helloPage(ModelAndView mv) {
		mv.setViewName("hello");
		return mv;
	}

}

Add support jar for jsp

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

Start it and you can access

If you need to support jstl, etc. 

Add the corresponding jar

  <dependency>

           <groupId>javax.servlet</groupId>

           <artifactId>jstl</artifactId>

       </dependency>
       <!-- servlet 依赖. -->

       <dependency>

           <groupId>javax.servlet</groupId>

           <artifactId>javax.servlet-api</artifactId>

           <scope>provided</scope>

       </dependency>

 

Guess you like

Origin blog.csdn.net/xiaodujava/article/details/89376652