Mar*_*itt 11 java spring spring-mvc url-pattern
我正在尝试运行第一个Spring 3 MVC设置.
我的应用程序在tomcat上运行,在"葡萄藤"的服务器环境中运行
出于测试目的,我正在尝试从中提取请求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'
Run Code Online (Sandbox Code Playgroud)
我必须在某个地方错误地配置它,但我看不出我做错了什么.
这是所有相关的片段.
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>
Run Code Online (Sandbox Code Playgroud)
从我的背景来看:
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
控制器:
@Controller
public class ParticipantInvitationController {
@RequestMapping("/test")
public ModelAndView test()
{
return new ModelAndView("noSuchInvitation");
}
Run Code Online (Sandbox Code Playgroud)
日志:
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
Run Code Online (Sandbox Code Playgroud)
ska*_*man 27
这是因为<url-pattern>在你web.xml的"太宽".值/*表示servlet配置为接收所有请求,包括从servlet到JSP的请求.您看到的错误消息来自DispatcherServlet,它正在接收自己的转发请求.
你应该选择一个更具体的<url-pattern>,例如<url-pattern>/xyz/*</url-pattern>,以便你的URL成为http://localhost:8080/grapevine/xyz/test,然后它应该工作正常.