<--------------------------控制类------------------------->
<---------------------定义commandClass-------------------->
public class FileUploadBean {
private byte[] file;
public void setFile(byte[] file) {
this.file = file;
}
public byte[] getFile() {
return file;
}
}
<---------------------定义commandClass-------------------->
4:定义一个form表单index.jsp
<form method="post" action="upload.htm" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>
5:定义confirmation.jsp及fail.jsp
confirmation.jsp如下:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
successView
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Upload Successful
</h1>
</body>
</html>
fail.jsp如下:
<html>
<head>
<title>Upload a file please</title>
</head>
<body>
<h1>no file,Please upload a file</h1>
<form method="post" action="uploadfile.htm" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>
</form>
</body>
</html>
6:运行tomcat。
预览 ie里面:http://localhost/springmvc/index.jsp
注:
a:文件目录为tomcat-HOME/webapps/springmvc/
.jsp文件都放在根目录下,.class文件放在/WEB-INF/classes/中
其他文件放在/WEB-INF/里面。
b:如果连上面的你都有疑问,那还是去看看spring的基础知识吧。