Springboot the integrated JSP for getting Started

Source: Internet
Author: User

Originally intended to continue to write thymeleaf aspects of the content, a look at the content of a lot of, maybe a week can not finish, and from the controller to get value and other content can also be from the online Baidu, so wrote the Springboot integrated JSP. Whether Thymeleaf or JSP is actually the embodiment of layered thought.

First, the introduction of dependency

or use the previous blog's demo, on its basis to modify, this time is the integration of JSP, so the first to introduce the JSP dependency. You need to remove the thymeleaf from 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>

Second, create JSP page

Since is the integration JSP, certainly has the JSP page, here I put the JSP page login.jsp under the/demo/src/main/webapp/view. Gets the value of a variable in the controller in the 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><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>name: ${name}<BR></Body></HTML>

Third, the configuration

Configure the prefix suffix of the view in Application.properties.


Iv. Creating a Controller


 PackageCom.example.demo;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod, @Controller @requestmapping ("/login") Public classLogin {@RequestMapping (value= "/login.do", method =requestmethod.get) PublicString Hello (model model) {Model.addattribute ("Name", "Cuiyw"); return"Login"; }}

V. Testing

Input http://localhost:8080/login/login.do

Springboot the integrated JSP for getting Started

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.