gpt4 book ai didi

java - 将文件从jsp发送到action

转载 作者:行者123 更新时间:2023-11-30 08:00:15 26 4
gpt4 key购买 nike

我必须将文件从 jsp 传递到 portlet 操作类 (java)。我在我的 jsp 中创建了这一行..

<input type="file" name="file"/>

但是当我需要将它传递到我的 portlet 时,我不知道如何处理它..我应该使用 ParamUtil.getXXX() 方法来处理它,但我没有看到任何保存文件数据的内容类型..它应该看起来像这样

String tin = ParamUtil.getString(actionRequest, "tin");
String surName = ParamUtil.getString(actionRequest, "surName");
String middleName = ParamUtil.getString(actionRequest, "middleName");
String givenName = ParamUtil.getString(actionRequest, "givenName");
String nameExt = ParamUtil.getString(actionRequest, "nameExt");
File file = ParamUtil. **<----- this is where I'm stuck :(**
Date birthDate = ParamUtil.getDate(actionRequest, "birthdate", DateFormat.getInstance());
String birthPlace = ParamUtil.getString(actionRequest, "birthplace");
String citizenship = ParamUtil.getString(actionRequest, "citizenship");
String civilStatus = ParamUtil.getString(actionRequest, "civilstatus");
String fatherFName = ParamUtil.getString(actionRequest, "fgivenName");
String fatherMName = ParamUtil.getString(actionRequest, "fmiddleName");
String fatherLName = ParamUtil.getString(actionRequest, "fsurName");
String motherFName = ParamUtil.getString(actionRequest, "mgivenName");
String motherMName = ParamUtil.getString(actionRequest, "mmiddleName");
String motherLName = ParamUtil.getString(actionRequest, "msurName");
String spouseFName = ParamUtil.getString(actionRequest, "sgivenName");
String spouseMName = ParamUtil.getString(actionRequest, "smiddleName");
String spouseLName = ParamUtil.getString(actionRequest, "ssurName");
String children[] = ParamUtil.getParameterValues(actionRequest, "children[]");


long pi_id = CounterLocalServiceUtil.increment();
personal_info pi = null;
pi = new personal_infoImpl();
pi = personal_infoLocalServiceUtil.createpersonal_info((int) pi_id);
pi.setTin(tin);
pi.setLname(surName);
pi.setFname(givenName);
pi.setMname(middleName);
pi.setName_ext(nameExt);
pi.setBirthDate(birthDate);
pi.setBirthplace(birthPlace);
pi.setPhoto(file); <------------ it's supposed to be saved in here.. but I'm stuck...

因此我什至没有测试过代码块..

最佳答案

您应该使用UploadPortletRequest来获取文件。

这就是我们对文件列表所做的操作。

JSP页面:

<form id="fileupload" method="POST" enctype="multipart/form-data" class="uploader-files pull-left">
<input type="file" name="fileUpload" multiple id="ofxUploadFile" class="file-uploader" />
....
....
</form>

Controller 方法:

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
File[] uploadedFileWithExtension = uploadRequest.getFiles("fileUpload");
InputStream[] inputStream = uploadRequest.getFilesAsStream("fileUpload");
File[] inputStreamUploadedFile = new File[inputStream.length];
int i = 0;
for (InputStream fileObj : inputStream) {
if (Validator.isNull(fileObj)) {
inputStreamUploadedFile[i] = FileUtil.createTempFile();
} else {
inputStreamUploadedFile[i] = FileUtil.createTempFile(fileObj);
}
i++;

}
}

关于java - 将文件从jsp发送到action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com