liferay中使用liferay-ui进行文件上传
2008-07-17 15:50
393 查看
在liferay中使用liferay-ui进行文件上传比较容易,效果还不错,下面我们来看都需要哪些代码
1,jsp页面中,见下面代码
<%
for (int i = 1; i <= 5; i++) {
%>
<tr>
<td>
<liferay-ui:message key="file" /> <%= i %>
</td>
<td>
<input name="<portlet:namespace />msgFile<%= i %>" size="70" type="file" />
</td>
</tr>
<%
}
%>
通过循环控制上传文件个数
2,我们再看action的部分,如下代码
List files = new ArrayList();
if (attachments) {
UploadPortletRequest uploadReq =
PortalUtil.getUploadPortletRequest(req);
for (int i = 1; i <= 5; i++) {
File file = uploadReq.getFile("msgFile" + i);
String fileName = uploadReq.getFileName("msgFile" + i);
byte[] bytes = FileUtil.getBytes(file);
if ((bytes != null) && (bytes.length > 0)) {
ObjectValuePair ovp = new ObjectValuePair(fileName, bytes);
files.add(ovp);
}
}
}
将request中的文件存放在list中
3,最后在service进行保存,如下代码
if (files.size() > 0) {
long companyId = issue.getCompanyId();
String portletId = CompanyImpl.SYSTEM_STRING;
long groupId1 = GroupImpl.DEFAULT_PARENT_GROUP_ID;
long repositoryId = CompanyImpl.SYSTEM;
String dirName = issue.getAttachmentsDir();
try {
try {
dlService.deleteDirectory(
companyId, portletId, repositoryId, dirName);
}
catch (NoSuchDirectoryException nsde) {
}
dlService.addDirectory(companyId, repositoryId, dirName);
for (int i = 0; i < files.size(); i++) {
ObjectValuePair ovp = (ObjectValuePair)files.get(i);
String fileName = (String)ovp.getKey();
byte[] byteArray = (byte[])ovp.getValue();
try {
dlService.addFile(
companyId, portletId, groupId1, repositoryId,
dirName + "/" + fileName, StringPool.BLANK,
new String[0], byteArray);
}
catch (DuplicateFileException dfe) {
}
}
}
catch (RemoteException re) {
throw new SystemException(re);
}
}
这样通过documentlibrary的DLService进行文件保存
1,jsp页面中,见下面代码
<%
for (int i = 1; i <= 5; i++) {
%>
<tr>
<td>
<liferay-ui:message key="file" /> <%= i %>
</td>
<td>
<input name="<portlet:namespace />msgFile<%= i %>" size="70" type="file" />
</td>
</tr>
<%
}
%>
通过循环控制上传文件个数
2,我们再看action的部分,如下代码
List files = new ArrayList();
if (attachments) {
UploadPortletRequest uploadReq =
PortalUtil.getUploadPortletRequest(req);
for (int i = 1; i <= 5; i++) {
File file = uploadReq.getFile("msgFile" + i);
String fileName = uploadReq.getFileName("msgFile" + i);
byte[] bytes = FileUtil.getBytes(file);
if ((bytes != null) && (bytes.length > 0)) {
ObjectValuePair ovp = new ObjectValuePair(fileName, bytes);
files.add(ovp);
}
}
}
将request中的文件存放在list中
3,最后在service进行保存,如下代码
if (files.size() > 0) {
long companyId = issue.getCompanyId();
String portletId = CompanyImpl.SYSTEM_STRING;
long groupId1 = GroupImpl.DEFAULT_PARENT_GROUP_ID;
long repositoryId = CompanyImpl.SYSTEM;
String dirName = issue.getAttachmentsDir();
try {
try {
dlService.deleteDirectory(
companyId, portletId, repositoryId, dirName);
}
catch (NoSuchDirectoryException nsde) {
}
dlService.addDirectory(companyId, repositoryId, dirName);
for (int i = 0; i < files.size(); i++) {
ObjectValuePair ovp = (ObjectValuePair)files.get(i);
String fileName = (String)ovp.getKey();
byte[] byteArray = (byte[])ovp.getValue();
try {
dlService.addFile(
companyId, portletId, groupId1, repositoryId,
dirName + "/" + fileName, StringPool.BLANK,
new String[0], byteArray);
}
catch (DuplicateFileException dfe) {
}
}
}
catch (RemoteException re) {
throw new SystemException(re);
}
}
这样通过documentlibrary的DLService进行文件保存
相关文章推荐
- 有关使用异步请求进行文件上传的方法
- springMVC 使用 goouploader 插件进行文件批量上传
- 使用versions进行SVN的版本管理,结果发现所有的.a文件都上传不上去
- 使用spring MVC框架进行文件上传
- 通过Ajax方式上传文件(input file),使用FormData进行Ajax请求
- Linux中使用rz sz进行上传下载文件
- 【java开发】使用MultipartFile进行文件上传的例子
- JSP中使用jspsmartupload组件进行文件的上传和下载
- 使用HttpUrlConnection进行post请求上传文件
- spring不使用插件进行文件上传返回数据
- 通过Ajax方式上传文件,使用FormData进行Ajax请求
- 使用FileUtils进行Java中Form表单上传文件
- linux下如何使用sftp命令进行文件上传和下载
- 使用libcurl进行文件、数据上传
- 使用sftp对文件进行上传或者是下载
- 使用ftp.storlines进行文件上传时出现553 Could not create file.的解决方法
- 在linux中使用rz,sz进行文件的上传和下载,用来代替SRT的sftp功能
- 使用ssh进行远程连接以及远程跳板以及scp远程上传下载文件说明
- 使用WebClient进行上传文件 [ZT]
- Java使用commons-fileupload进行文件上传