当前位置 : 主页 > 编程语言 > java >

Springboot(十九)SpringBoot整合jsp

来源:互联网 收集:自由互联 发布时间:2022-10-26
有些老的项目用的jsp,改造起来可能比较麻烦,如果springboot直接集成,那就方便多了 工程目录如下: 1.建立一个springboot工程,依赖如下,依赖上有说明 ?xml version="1.0" encoding="UTF-8"? p


有些老的项目用的jsp,改造起来可能比较麻烦,如果springboot直接集成,那就方便多了

工程目录如下:

Springboot(十九)SpringBoot整合jsp_spring

 

1.建立一个springboot工程,依赖如下,依赖上有说明

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.xhx.springboot</groupId>
<artifactId>springboot28</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>springboot28</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--servlet依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<!--jstl依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

<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>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

 

2.application.xml配置

spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp

3.jsp文件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Hello jsp
</body>
</html>

 

4.controller

package com.xhx.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* xuhaixing
* 2018/8/20 21:33
**/
@Controller
public class HelloController {

@RequestMapping(value = "index")
public String index(){
return "index";
}
}

 

启动程序,请求

Springboot(十九)SpringBoot整合jsp_spring_02

 

实时内容请关注微信公众号,公众号与博客同时更新:程序员星星

Springboot(十九)SpringBoot整合jsp_springboot_03

 

上一篇:Verilog HDL 实现 74HC595
下一篇:没有了
网友评论