I originally planned to continue writing about thymeleaf in this article. I saw that there was quite a lot of content, and I might not finish it in a week. I could also get value from Controller and other content from Baidu online, so I wrote Springboot integrated jsp. Whether it is thymeleaf or jsp, they are actually manifestations of layered ideas.
1. Introduce dependencies
I will use the demo of the previous blog and modify it based on it. This time I integrate jsp, so I need to introduce jsp dependencies first. Here you need to remove the thymeleaf added to the previous blog.
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency>
2. Create a jsp page
Since it is integrated with JSP, the jsp page is definitely indispensable. Here I put the jsp page login.jsp under /demo/src/main/webapp/view. Get a variable value in the Controller in 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>Insert title here</title></head><body>Name:${name}<br></body></html>3. Configuration
Configure the prefix suffix of the view in application.properties.
spring.mvc.view.prefix=/view/spring.mvc.view.suffix=.jsp
4. Create a Controller
exist
package com.example.demo;import org.springframework.steretype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@Controller@RequestMapping("/login")public class Login { @RequestMapping(value = "/login.do",method = RequestMethod.GET) public String hello(Model model) { model.addAttribute("name", "Cuiyw"); return "login"; }}V. Test
Enter http://localhost:8080/login/login.do
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.