Analysis of the principle of Jsp in Spring Boot

The essence of jsp

  • The essence of jsp is servlet. You have deployed Java Web project with tomcat, and you know how to generate the corresponding servlet of jsp page in the work directory.
  • The essence of servlet is to encapsulate socket

jsp page

  Created by IntelliJ IDEA.
  User: wy
  Date: 2019/11/26
  Time: Afternoon11:21
  To change this template use File | Settings | File Templates.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<a href="login">Sign in</a>

Corresponding Servlrt

ublic final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent,
                 org.apache.jasper.runtime.JspSourceImports {
  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
      throws, javax.servlet.ServletException {
    try {
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("    <title>Title</title>\n");
      out.write("        111111111111\n");
      out.write("<a href=\"login\">Sign in</a>\n");
    } catch (java.lang.Throwable t) {
    } finally {

Using jsp in SpringBoot

  • Spring boot does not support jsp by default. To make spring boot support jsp, you need to introduce the following dependencies
  • The complete dependencies are as follows:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
		<relativePath/> <!-- lookup parent from repository -->
	<description>Demo project for Spring Boot</description>







  • Write test program
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceView;

public class HelloController {

    public ModelAndView hello(){
        ModelAndView mv = new ModelAndView();
        InternalResourceView internalResourceView = new InternalResourceView("index.jsp");
        return  mv;

Create webapp folder in maven project, create index.jsp file, access http://localhost:8080/hello

Now we use the view parser of jsp in springboot, so where is the generated jsp file?

  • What is certain here is that as long as you use jsp as the view, you must generate the corresponding servlet file.
  • In linux system, the servlet page generated by jsp is in the / tmp file
├── tomcat.6136740723794350932.8080
│   └── work
│       └── Tomcat
│           └── localhost
│               └── ROOT
│                   └── org
│                       └── apache
│                           └── jsp
│                               ├── index_jsp.class
│                               └── index_jsp.

Note: the corresponding servlet page will be generated only when the corresponding jsp page is visited for the first time

Reference resources

Published 2 original articles, praised 0 and visited 8346
Private letter follow

Keywords: JSP Apache Tomcat Spring

Added by bastien on Tue, 11 Feb 2020 18:28:24 +0200