Spring MVC-页面未找到错误
问题描述:
我试图实现muliple file upload教程的变体,并且遇到了让应用程序运行的问题。Spring MVC-页面未找到错误
我创建使用模板在Eclipse中的Spring MVC项目。
控制器已被
@Controller
public class FileUploadController {
@RequestMapping(value = "/show", method = RequestMethod.GET)
public String displayForm() {
return "uploadForm";
}
@RequestMapping(value = "/save", method = RequestMethod.GET)
public String save(@ModelAttribute("uploadForm") FileUploadForm uploadForm, Model map) {
//get file name and copy to server location
return "uploadSuccess"
}
其中uploadForm
和uploadSuccess
是我的web.xml文件中被定义为
<display-name>SampleFileUpload</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
内Views
JSP页面和spring-servlet.xml
文件中实现被定义为
<context:annotation-config />
<context:component-scan base-package = "com.jasonjohns.spring.fileupload.controller" />
<bean id = "multipartResolver" class =
"org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean id = "jspViewResolver" class =
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "viewClass" value =
"org.springframework.web.servlet.view.JstlView" />
<property name = "prefix" value = "/WEB-INF/views/" />
<property name = "suffix" value = ".jsp" />
</bean>
但是,当我启动应用程序没有发现错误,exept服务器返回404错误,即使当我去localhost:8080/SampleFileUpload/show.html
。你猜猜它是一个控制器错误,但我不明白它背后是什么。
答
你尝试更改的映射:
@RequestMapping(值= “/秀”,方法= RequestMethod.GET)
到
@RequestMapping(值=“/节目。 html“,method = RequestMethod.GET)
它是否说'show.html'不可用或'uploadForm.jsp'? – zeroflagL 2013-05-04 17:57:06