为什么我的JSP视图没有得到解决? [英] Why is my JSP view not being resolved?

查看:149
本文介绍了为什么我的JSP视图没有得到解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的dispatcher-servlet.xml

My dispatcher-servlet.xml

   <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
        <mvc:annotation-driven/>
        <context:component-scan base-package="com.example" />

    <bean id="viewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView"/>  

</beans>

这是我的控制器

package com.example.spring;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

        @RequestMapping("/form.htm")
        public ModelAndView hello(Model model) {
                return new ModelAndView("index");
        }
}

我在应用程序中看到这个在调试中。

I see this in my console when I have the app in debug.

WARNING: No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcher'

控制器被点击,并返回视图,但它可以'要解决。

The controller gets hit, and returns the view, but then it can't be resolved.

推荐答案

听起来你可能在 web.xml中遗漏了以下内容

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/WEB-INF/views/*</url-pattern>
</servlet-mapping>

正如@Javi已经评论过的,这是已经在这里回答

As @Javi already commented, this is already answered here.

这篇关于为什么我的JSP视图没有得到解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆