代码之家  ›  专栏  ›  技术社区  ›  Marty Pitt

使用InternalResourceViewResolver的基本Spring MVC配置:pageNotFound

  •  11
  • Marty Pitt  · 技术社区  · 15 年前

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

    我的应用程序运行在Tomcat上,服务器上下文为“Grapevine”

    为了测试的目的,我尝试从 http://localhost:8080/grapevine/test 呈现 WEB-INF/jsp/noSuchInvitation.jsp

    当我尝试这个的时候,我得到了一个 404 日志显示我的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'
    

    我一定是在某个地方配置错误,但我看不出我做错了什么。

    以下是所有相关的片段。

    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
    
    5 回复  |  直到 11 年前
        1
  •  27
  •   skaffman    15 年前

    <url-pattern> web.xml /* DispatcherServlet

    < <url-pattern>/xyz/*</url-pattern> http://localhost:8080/grapevine/xyz/test

        2
  •  2
  •   Alfergon    13 年前

    /* / url-pattern

        3
  •  1
  •   Community Mohan Dere    9 年前

    <servlet>
        <servlet-name>RestServlet</servlet-name>
        <servlet-class>
           org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    
    <servlet-mapping>
      <servlet-name>RestServlet</servlet-name>
      <url-pattern>/</url-pattern>
      <url-pattern>*.html</url-pattern>
      <url-pattern>*.json</url-pattern>
     </servlet-mapping>
    

    /*

    <mvc:default-servlet-handler/> 
    

    <servlet-mapping>
      <servlet-name>jsp</servlet-name>
      <url-pattern>/WEB-INF/jsp/*</url-pattern>
     </servlet-mapping>
    
    <servlet>
      <servlet-name>jsp</servlet-name>
      <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    </servlet>
    

    spring web.xml

        4
  •  0
  •   David Lotts    12 年前

    <property name="prefix" value="/WEB-INF-typo-Here/jsp/"/>
    

        5
  •  0
  •   appsthatmatter    11 年前

    推荐文章