[英]Spring: ModelAndView can't locate view
This controller fails to find the view "index": 该控制器找不到视图“索引”:
@RequestMapping("/test2")
public ModelAndView test2() throws Exception {
return new ModelAndView("index");
}
It returns a 404 error, with the following in the GlassFish console: 它返回404错误,并在GlassFish控制台中显示以下内容:
Severe: PWC6117: File "null" not found
That is strange because this controller finds it ok: 这很奇怪,因为此控制器认为可以:
@RequestMapping("/test")
public String test() throws Exception {
return "index";
}
My project is NetBeans default Spring Web MVC project (using 4.0.1). 我的项目是NetBeans的默认Spring Web MVC项目(使用4.0.1)。 The only config change is to add this to applicationContext.xml: 唯一的配置更改是将其添加到applicationContext.xml:
<mvc:annotation-driven/>
<context:component-scan base-package="myapp"/>
It seems that either I'm using ModelAndView incorrectly, or for some reason it's using different view resolution. 看来我是错误地使用了ModelAndView,或者由于某种原因它正在使用不同的视图分辨率。
For reference, this is the view resolver: 供参考,以下是视图解析器:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
And this is the web.xml for the dispatcher: 这是调度程序的web.xml:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
I can't say with no doubt because you didn't post your list of importations of the code, but i think this error (404 not found) occurs when you import "org.springframework.web.portlet.ModelAndView" instead of "org.springframework.web.servlet.ModelAndView" One is used for portlets, the other for servlets. 我不能肯定地说,因为您没有发布代码的导入列表,但是我认为当您导入“ org.springframework.web.portlet.ModelAndView”而不是“”时,会出现此错误(找不到404) org.springframework.web.servlet.ModelAndView“,其中一个用于portlet,另一个用于servlet。 Most of the ide's imports the firs one automaticaly. 多数思想家自动进口冷杉。
就我而言,这是错误的文件夹名称,因为您知道将项目从Windows移至Linux时,您的WEB-INF文件夹将名称更改为小写,当然在这种情况下,您的ModelAndView在战争中无法找到.jsp文件的正确路径,而您需要做的所有事情是大写的WEB-INF文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.