将多个文件上传为目录

时间:2018-11-12 01:01:06

标签: jsp upload

我正在尝试使用jsp将多个文件上传为目录。 我上传了多个文件,但是目录结构坏了。

这是fileUploadForm.jsp

<%@ page language="java" import="com.oreilly.servlet.multipart.*"%>
<body>
    <form action="fileUpload.jsp" method="post" enctype="multipart/form-data">
    <table align="center" border="1">
    <tr>
        <td colspan="2">Mobile Engine Signature Upload</td>
    </tr>
    <tr>
        <td>Engine Signature</td>
        <td><input type="file" name="engine" webkitdirectory mozdirectory directory></td>
    </tr>
    <tr>
        <td colspan="2"><input type="submit" value="Upload"></td>
    </tr>
    </table>
</body>

这是fileUpload.jsp

<%@ page language="java" import="com.oreilly.servlet.multipart.*, com.oreilly.servlet.*, java.util.Enumeration, java.io.*"%>
<% String uploadPath = request.getRealPath("engine");

int size = 10*1024*1024;
String filename="";
String path="";

try{
    MultipartRequest multi=new MultipartRequest(request,uploadPath,size,"euc-kr",new DefaultFileRenamePolicy());

    Enumeration files = multi.getFileNames();
    String engine = (String)files.nextElement();
    filename = multi.getFilesystemName(engine);
}catch(Exception e){
    e.printStackTrace();
}
%>

<body>
<form name="filecheck" action="fileCheck.jsp" method="post">
<input type="hidden" name="engine" value="<%=filename %>">
<a href="#" onclick="javascript:filecheck.submit()">Check Upload and go to Download Page</a>
</body>

0 个答案:

没有答案