<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
// decode source request:
try {
MultipartFormDataRequest multiPartRequest = new MultipartFormDataRequest(request);
// get the files uploaded:
Hashtable files = multiPartRequest.getFiles();
ZipFile userFile = (ZipFile)files.get("bootstrap_file");
if (! files.isEmpty()) {
BootstrapDataManager bdm = new BootstrapDataManager(userFile);
bdm.bootstrapStudent();
bdm.bootstrapCourse();
bdm.bootstrapSection();
bdm.bootstrapBid();
bdm.bootstrapCompletedCourses();
bdm.bootstrapPreRequisite();
}
} catch (Exception error) {
// set error flag in session:
request.getSession().setAttribute("error", error);
// throw its further to print in error-page:
throw error;
}
%>
</body>
</html>
BidDataManager在其构造函数中接受ZipFile对象,我想知道如何将UploadFile对象转换为ZipFile对象,以便将其作为参数传递。
答案 0 :(得分:0)
必须有一个返回InputStream
的方法,以便您可以像FileOutputStream
一样将其写入uploadFile.getInputStream()
,或者采用File
类似uploadFile.write(file)
的方法1}}。
无论哪种方式,您都需要以File
结尾,以便将其传递给ZipFile
的构造函数。如有必要,您可以使用File#createTempFile()
将其设为TEMP文件,这样您就不必担心清理。
无论如何,JSP是这项工作的错误地方。我建议在为时已晚之前学习servlet。