我正在尝试实现多文件上传教程的变体,并且在让应用程序运行时遇到问题。
我使用模板在 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
JSPuploadSuccess
页面在哪里?Views
我的 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>
并且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>
但是,当我启动应用程序时,没有发现任何错误,除了服务器返回 404 错误,即使我转到localhost:8080/SampleFileUpload/show.html
. 你猜它是一个控制器错误,但我不明白它背后的原因。