Spring MVC,Return ModelAndView 语句在 Controller 中被忽略
我有以下应用程序设置。
- 调度程序 Servlet 与
*.htm
URL 模式匹配。 - 控制器有注释
@RequestMapping(value = "doSuccess")
- 上述注释的方法只是返回
new ModelAndView("success");
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"
p:order="1"/>
- 索引页有链接
<a href="doSuccess.htm">Click me</a>
- There是一个名为
success.jsp
的文件,位于/WEB-INF/jsp/
现在,当我单击“Click me”时,我得到一个 404。我做了一些调试并意识到控制器中的方法确实被调用,但无论返回语句如何,它都会尝试查找doSuccess.htm
。
I have following app setup.
- The dispatcher servlet is matched to the
*.htm
URL pattern. - Controller has the annotation
@RequestMapping(value = "doSuccess")
- The method for the above annotation just returns
new ModelAndView("success");
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"
p:order="1"/>
- The index page has the link
<a href="doSuccess.htm">Click me</a>
- There is a file called
success.jsp
located in/WEB-INF/jsp/
Now, when I click on the Click me, I get a 404. I did a bit of debugging and realized that the method in the controller was indeed being called but irrespective of the return statement it is trying to find doSuccess.htm
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了错误。我使用的是 Netbeans,并且使用了自动完成导入。它正在导入 org.springframework.web.portlet.ModelAndView 而不是 servlet.ModelAndView。
I figured the error. I was using Netbeans and i used the auto complete imports. It was importing the org.springframework.web.portlet.ModelAndView instead of servlet.ModelAndView.