Basic Spring MVC配置:使用InternalResourceViewResolver的PageNotFound [英] Basic Spring MVC config: PageNotFound using InternalResourceViewResolver

查看:250
本文介绍了Basic Spring MVC配置:使用InternalResourceViewResolver的PageNotFound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行第一个Spring 3 MVC设置。

I'm trying to get a first Spring 3 MVC setup running.

我的应用程序在tomcat上运行,服务器上下文为grapevine

My app is running on tomcat, with in the server context of "grapevine"

出于测试目的,我试图从 http:// localhost:8080 / grapevine / test 呈现的内容WEB-INF / jsp / noSuchInvitation.jsp

For the purposes of testing, I'm trying to get requests from http://localhost:8080/grapevine/test to render the contents of WEB-INF/jsp/noSuchInvitation.jsp

当我试试这个时,我'得到 404 ,日志表明我的jsp不存在:

When I try this, I'm getting a 404, and the logs suggest that my jsp isn't present:

WARN  org.springframework.web.servlet.PageNotFound  - No mapping found for HTTP request with URI [/grapevine/WEB-INF/jsp/noSuchInvitation.jsp] in DispatcherServlet with name 'grapevine'

我必须在某处错误配置,但我看不出我做错了什么。

I must have mis-configured this somewhere, but I can't see what I've done wrong.

以下是所有相关摘录。

Web.xml:

<servlet>
    <servlet-name>grapevine</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>grapevine</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

从我的背景信息:

<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

控制器:

@Controller
public class ParticipantInvitationController {

@RequestMapping("/test")
public ModelAndView test()
{
    return new ModelAndView("noSuchInvitation");
}

日志:

DEBUG org.springframework.web.servlet.DispatcherServlet  - Rendering view [org.springframework.web.servlet.view.JstlView: name 'noSuchInvitation'; URL [/WEB-INF/jsp/noSuchInvitation.jsp]] in DispatcherServlet with name 'grapevine'
DEBUG org.springframework.web.servlet.view.JstlView  - Forwarding to resource [/WEB-INF/jsp/noSuchInvitation.jsp] in InternalResourceView 'noSuchInvitation'
DEBUG org.springframework.web.servlet.DispatcherServlet  - DispatcherServlet with name 'grapevine' processing GET request for [/grapevine/WEB-INF/jsp/noSuchInvitation.jsp]
WARN  org.springframework.web.servlet.PageNotFound  - No mapping found for HTTP request with URI [/grapevine/WEB-INF/jsp/noSuchInvitation.jsp] in DispatcherServlet with name 'grapevine'
DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository  - SecurityContext contents are anonymous - context will not be stored in HttpSession. 
DEBUG org.springframework.web.servlet.DispatcherServlet  - Successfully completed request


推荐答案

这是因为 web.xml 中的< url-pattern> 也是宽。值 / * 表示servlet配置为接收所有请求,包括从servlet到JSP的请求。您看到的错误消息来自 DispatcherServlet ,它正在接收自己转发的请求。

This is because the <url-pattern> in your web.xml is too "wide". A value of /* means that the servlet is configured to receive all requests, and that includes the request from the servlet to the JSP. The error message you're seeing is from DispatcherServlet, which is receiving its own forwarded request.

您应该选择更具体的< url-pattern> ,例如< url-pattern> / xyz / *< / url-pattern> ,以便您的网址变为 http:// localhost:8080 / grapevine / xyz / test ,然后它应该可以正常工作。

You should pick a more specific <url-pattern>, e.g. <url-pattern>/xyz/*</url-pattern>, so that your URL then becomes http://localhost:8080/grapevine/xyz/test, and then it should work fine.

这篇关于Basic Spring MVC配置:使用InternalResourceViewResolver的PageNotFound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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