**Eclipse Springboot项目 controller跳转访问JSP**

Eclipse Springboot项目 controller跳转访问JSP

1、在main文件夹下创建/webapp/WEB_INF/JSP/oldIndex.jsp
在这里插入图片描述

2、设置webapp为Source Folder

  • 右击项目 > build path > Configure build path
  • 点击add folder

在这里插入图片描述在这里插入图片描述
3、在pom.xml加入jsp依赖

<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
             <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId> 
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jsp-api</artifactId>
        </dependency>

4、在application.yml中加入mvc配置
(删除application.properties新建appliction.yml,推荐使用appliction.yml)

spring.mvc.view.prefix: /WEB_INF/JSP/
spring.mvc.view.suffix: .jsp

5、新建的controller、service、model、dao应该在springboot项目启动类的包内,否则可能出现运行错误
在这里插入图片描述6、创建TestController类

package com.example.controller;

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

@Controller
public class TestController {
	@RequestMapping("/TEST")
	public String test() {
		return "oldIndex";
	}
}

7、运行启动类,浏览器输入
http://localhost:8080/TEST
如果出现下面错误
Error resolving template [oldIndex], template might not exist or might not be accessible by any of the configured Template Resolvers

注释掉

<!-- 		<dependency>
    		<groupId>org.springframework.boot</groupId>
   			 <artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency> -->

重新运行项目
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值