Modified SpringBoot java project to web project

1. The following references need to be added in Pom to parse jsp files.

        <dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>

Otherwise, when accessing jsp, it will change to download mode. At this time, springboot is used as a web server.

The file structure is as follows:

At this point, visit  http://localhost:8081/index.jsp , and the page is parsed normally.

Okay, no problem, the jsp is parsed. But we need business logic processing and page jumps.

2. Configure the controller and increase the index.jsp jump page

@Controller
public class WorkStaticsController {
    @RequestMapping(value = "/home", method = {RequestMethod.GET, RequestMethod.POST})
    private ModelAndView home() {
		ModelAndView mode = new ModelAndView();
		mode.addObject("name", "zhangsan");
		mode.setViewName("index");
		return mode;
    }
    @RequestMapping(value = "/home1", method = {RequestMethod.GET, RequestMethod.POST})
    private Object download1() {
    	return "index";
     }
 }

Well, let's visit home and home1.

However, spring gave us this page:

Obviously, Spring did not find the index page.

It turns out that we also need to configure in application.properties

spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
告诉spring,页面后缀以及路径。

After the configuration is complete, go to visit:

Okay, let me talk about that first.

Guess you like

Origin blog.csdn.net/H517604180/article/details/88879593