Springboot Project Add JSP support

Source: Internet
Author: User

I. creating a Springboot project

Use http://start.spring.io/to quickly create a springboot project to download and import

Two. Add dependencies

The following dependencies are added to support JSP in Pom.xml:

<!--web-dependent--><dependency> <groupId>org.springframework.boot</groupId> &lt ;artifactid>spring-boot-starter-web</artifactid></dependency> <!--servlet dependent-< Dependency> <groupId>javax.servlet</groupId> &LT;ARTIFACTID&GT;JAVAX.SERVLET-API&L                T;/artifactid> <scope>provided</scope> </dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId></dependency> & lt;!                --Tomcat's support .--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> < /dependency><dependency> <groupId>org.apache.tomcat.embed</groupId> &lt ; artifactid>tomcat-embed-jasper&Lt;/artifactid> </dependency> 

Three. Writing a controller

@Controller  Public class Logincontroller {        @RequestMapping (value= "/login")    public  String Hello () {         return "Login";    }    }

Note that at this point the annotations are @controller and cannot be used @restcontroller

Four. Configure the JSP-enabled configuration file application.properties

# #jsp  # #spring. Mvc.view.prefix=/web-inf/jsp/spring.mvc.view.suffix=.jsp

Five. Writing JSP pages

Add webapp/web-inf/jsp folder under Project Project Src/main directory, add JSP page

<%@ 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" >Hello!!! </body>

Six. Start Project startup class Access Controller path

Description

1,freemarker
2,groovy
3,thymeleaf ( Use this on spring website)
4,velocity
5,spring Boot official does not recommend using JSP, STS created project will have a templates directory under Sec/main/resources, here is let us put the template file, and then did not generate such as Springmvc WebApp directory)

Springboot Project Add JSP support

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.