我正在尝试运行第一个Spring3MVC设置。
我的应用程序运行在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发布于 2013-03-19 07:57:45
只需将/*替换为/作为url-pattern即可。会管用的..。
发布于 2013-02-12 10:35:49
解决方案1:您可以在*.html和*.json (或*.html、gif、png.)注册servlet:
<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>解决方案2:如果希望将servlet映射到/*,请将以下内容添加到spring.xml文件中:
<mvc:default-servlet-handler/> 下面是您的web.xml文件:
<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>发布于 2013-12-28 04:27:14
小心:这可能是一条误导性错误信息。就发生在我身上。
即使错误消息意外地包含/ContextName/.在路径的开头,它仍然可能是InternalResourceViewResolver前缀中的拼写错误:
<property name="prefix" value="/WEB-INF-typo-Here/jsp/"/>或者文件路径本身。
现在我已经改正了我的拼写错误,效果很好。我不知道为什么上下文显示在错误信息中,这真的使我忽略了我愚蠢的错误,并试图尝试对这个问题做出其他精彩的贡献。别让它发生在你身上!
顺便说一下,我正在使用Spring4.0.0发行版。
https://stackoverflow.com/questions/3878957
复制相似问题