Springboot整合jsp出现Could not resolve view with name Index in servlet with name dispatcherServlet

10 篇文章 0 订阅
9 篇文章 0 订阅

新手在学Springboot整合jsp的时候出现的一个问题
在这里插入图片描述

问题描述:

无法在名称为“ dispatcherServlet”的servlet中解析名称为“ Index”的视图

问题分析:

在控制层:

 @RequestMapping("/TestIndex")
    public ModelAndView Test() {
        System.out.println("hello");
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg", "Hello,Springboot");
        mv.setViewName("Index");
        return mv;
    }

按住ctrl加鼠标 的时候可以跳转过去,说明本身没啥问题,但就是一直报错,
突然想到了dispathServlet是mvc框架的东西,会不会是那边的问题。
在之前这项目弄过Springboot整合Springmvc的时候,出现一个工具类


package com.example.springboot.demo01.Config;

import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@EnableWebMvc
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/userHello").setViewName("Hello");
    }
}


注解@EnableWebMvc

 将此注释添加到@Configuration类中将导入Spring MVC配置
解决方案

将注解@EnableWebMvc去掉即可

运行结果:
在这里插入图片描述
一个小小的问题弄了半天,我也是佛了,大家不要学我把大部分整合案例放在一个工程里,以免出现不必要的麻烦,可以新建模块,进行学习整合。

  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值