将UploadFile对象转换为ZipFile对象 JSP页面
BidDataManager在其构造函数中接受ZipFile对象,我想知道如何将UploadFile对象转换为ZipFile对象,以便将其作为参数传递。必须有一个方法返回将UploadFile对象转换为ZipFile对象 JSP页面,jsp,Jsp,BidDataManager在其构造函数中接受ZipFile对象,我想知道如何将UploadFile对象转换为ZipFile对象,以便将其作为参数传递。必须有一个方法返回InputStream,以便您可以自己将其写入FileOutputStreamuploadFile.getInputStream(),或采用文件的方法,如uploadFile.write(File) 无论哪种方式,您都需要得到一个文件,以便将其传递给ZipFile的构造函数。如有必要,您可以使用将其作为临时文件,这样就不必担心清
InputStream
,以便您可以自己将其写入FileOutputStream
uploadFile.getInputStream()
,或采用文件
的方法,如uploadFile.write(File)
无论哪种方式,您都需要得到一个文件
,以便将其传递给ZipFile
的构造函数。如有必要,您可以使用将其作为临时文件,这样就不必担心清理问题
无论如何,JSP对于此作业来说是错误的。我建议学习servlet,以免为时已晚。请添加适当的语言/平台标记。非常感谢。如果你要包含一个代码示例,请将其正确格式化,并确保至少括号匹配。我已经添加了必要的信息。。你知道我能做什么吗?
<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>