我尝试将文件夹的内容上传到服务器。但是我做不到,所以我举了一个例子,你必须选择每一个文件。将文件夹上传到服务器(mvc spring)
控制器:
@Controller
public class FileUploadController {
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@ModelAttribute("uploadForm") FileUploadForm uploadForm,Model map) {}
}
和JSP文件
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<title> - Upload</title>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
//add more file components if Add is clicked
$('#addFile').click(function() {
var fileIndex = $('#fileTable tr').children().length;
$('#fileTable').append(
'<tr><td>'+
' <input type="file" name="files['+ fileIndex +']" />'+
'</td></tr>');
});
});
</script>
</head>
<body>
<div align="center" class="jumbotron">
<h1>dd</h1>
<form:form method="post" action="save.html"
modelAttribute="uploadForm" enctype="multipart/form-data">
<p>Dateien auswählen zum uploaden</p>
<input class="btn btn-success" id="addFile" type="button" value="Datei hinzufügen" />
<table align="center" class="table table-striped" id="fileTable">
<tr>
<td><input name="files[0]" type="file" /></td>
</tr>
<tr>
<td><input name="files[1]" type="file" /></td>
</tr>
</table>
<br/><input class="btn btn-primary" type="submit" value="Upload" />
</form:form>
</div>
</body>
</html>
那伟大工程。我发现了一些例子,我可以一次选择多个文件(只需添加多个文件),但不能上传它们。我得到了一些麻烦,让这个工作。我很惊讶它很难做到这么简单的事情。我不知道我是否必须更改我的控制器文件或只有我的jsp文件。我希望有人能将我的想法告诉我。我是新来的,所以请跟我说说喜欢一个小傻瓜。 电贺 山姆