Foreword
JavaServer Pages (JSP) technology allows Web developers and designers to rapidly develop and easily maintain information-rich dynamic Web pages using the existing business systems.
As part of the Java technology family, JSP technology to quickly develop Web-based applications platform-independent. JSP technology separates the user interface from content generation separately, allowing designers to change the overall page layout without altering the underlying dynamic content.
Benefits for developers
If you are familiar with HTML web developer or designer, you can:
JSP technology without having to learn the Java language : You can use JSP technology without having to learn how to write Java scriplet. Although no longer need scriptlet to generate dynamic content, but they are still supported for backward compatibility.
Extended JSP Language : Java tag library developers and designers can use the "simple tag handlers" extension JSP language, the tag handler to use the new, simpler, clearer markup extension API. This stimulates the available removable, reusable libraries of increasing the number of markers, thereby reducing the amount of code required to write powerful features of the Web application.
Easy to write and maintain pages : JavaServer Pages and the Standard Tag Library (JSTL) expression language is now integrated into the JSP technology, and has been upgraded to support. You can now use the expression language instead of scriptlet expressions.
- The above is an excerpt from Oracle JSP presentation on the link address: https://www.oracle.com/technetwork/java/overview-138580.html
Although JSP has basically been eliminated, but many companies are still using the old project as JSP pages, by reading this blog post, you will quickly learn how to use JSP simple operation SpringBoot in.
Procedure using JSP SpringBoot
The first step to add support for JSP view dependency in pom.xml, specific code as follows:
<!-- 非必选 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Provided 编译和测试的时候使用-->
<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>
The second step was added application.properties JSP configuration information in the configuration file, the specific configuration is as follows:
server.port=8080
server.servlet.context-path=/sbe
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
The third step is to create a src / main / webapp directory and create a JSP in the directory.
Add JSP file path location shown below:
JSP document reads as follows:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
${welcome}
</body>
</html>
The fourth step to create an access Controller JSP pages.
package cn.lijunkui.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping()
public class JspController {
@RequestMapping("/helloworld")
public String toJps(Model model) {
model.addAttribute("welcome", "不建议使用jsp");
return "welcome";
}
}
test
Enter Access Controller JSP pages in the tour is the URL of: HTTP: // localhost: 8080 / SBE / the HelloWorld test, the test results are as follows:
summary
SpringBoot JSP using the following steps:
- Introducing spring-boot-starter-tomcat dependent and scope as provided
- In the profile view application.properties arranged jsp
- Creating WEB-INF directory create src / main / webapp directory and create a JSP file in the directory
- Creating the JSP Access Controller
The sample code
Specific code examples, please see my GitHub repository springbootexamples the module project name: the Spring JSP-the Boot-2.x- view
GitHub: https://github.com/zhuoqianmingyue/springbootexamples
If you are interested in these, welcomed the star, or point-like support! Please indicate the source forwarding!