First, Springboot integrated JSP:
<!--集成jsp所需jar包--><!--jsp页面使用jstl标签--><dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId></dependency><!-- tomcat 的支持.--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope></dependency><!--用于编译jsp--><dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <!--<scope>provided</scope>--></dependency>
- 2. APPLICATION.YML Configuration
server: port: 8100 spring: mvc: view: prefix: /WEB-INF/jsp/ # 页面默认前缀目录 suffix: .jsp # 响应页面默认后缀
3, write the startup class, inherit the Springbootservletinitializer class, and rewrite the Configure method
The role of this class is similar to configuring the Listener in Web. Xml to initialize the spring application context, except that there is no need to write additional XML files here.
4. Write Controller
Must be a @controller annotation, if it is @restcontroller need to use the new Modelandview ("First/hello");
Directory structure
- 6, start the project, visit Http://localhost:8100/first
You can successfully access the JSP file.
Note: On the internet to find a lot of blogs, are said to be under Main to create a WebApp file, set as the Web, in the Web to create web-inf/jsp, but I have tried so many times, have not access, error page can not find, I this JSP file is under the resources directory under the META-INF/RESOURCES/WEB-INF/JSP, otherwise access to JSP II, from the form login
- 1, pom file and configuration file invariant code in the login folder, is to use @restcontroller annotations and Modelandview implementation Access JSP page
Source
Springboot Integrated JSP