我正在尝试实现muliple file upload教程的变体,并且在运行应用程序时遇到问题。
我使用模板在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
是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>
但是,当我启动应用程序时没有发现错误,即使我转到localhost:8080/SampleFileUpload/show.html
,服务器也会返回404错误。你猜它是一个控制器错误,但我无法理解它背后的原因。
答案 0 :(得分:0)
您是否尝试更改映射:
@RequestMapping(value =“/ show”,method = RequestMethod.GET)
到
@RequestMapping(value =“/ show.html”,method = RequestMethod.GET)