




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
很多时候,我们会遇到这种需求:用户需要上传csv数据文件到EBS服务器,然后程序读取数据到数据库。不同的用户上传的路径也不同,比如采购用户,需要上传采购数据,BOM用户,需要上传BOM清单,财务用户需要上传日记账数据,等等。实现方式有很多。比如,DBA在服务器端分别共享文件夹给不同的用户,文件夹设置密码(这个方式最便捷,我公司就是用这种方式)。本帖简单实现的是另外一个方法,在EBS注册一个OAF页面,通过javaftp的方式,把文件上传到EBS服务器。如下图:用户应该可以选择需要上传的路径。(数据可以在value set设置,具体权限控制需要自己酌情考虑)OAF截图:java代码:(简单测试通过,能从本机把文件上传到EBS服务器上,参数都是写死的硬代码)MyFtp.javapackage oracle.apps.ak.uploadfile.webui;/java ftp upload import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import .TelnetOutputStream; import .ftp.FtpClient; import sun.security.action.OpenFileInputStreamAction; public class MyFtp public static void SimonTestFTP(String serverPath) MyFtp ftpTest = new MyFtp(); /UploadCO ftpTest = new UploadCO(); String serverUrl = hostname; String userName = username; String passWord = password; String uploadFile = D:/SIMON_TEST_FTP.csv; /String serverPath = server path; /上传文件到Ftp服务器 ftpTest.uploadToFtpServer(serverUrl , userName, passWord, uploadFile, serverPath); public void uploadToFtpServer(String serverUrl, String userName, String passWord, String uploadFile, String serverPath) FtpClient ftpClient; try ftpClient = new FtpClient();/打开ftp客户端 /登录到Ftp服务器 boolean isOpenSuccess = loginToFtpServer(ftpClient, serverUrl, userName, passWord); if (isOpenSuccess) /以下几步顺序不能错 /进入服务器的指定目录 ftpClient.cd(serverPath); OutputStream outputStream = getFtpClientOutputStream(ftpClient, uploadFile); InputStream inputStream = getLocalFileInputStream(uploadFile); writeToFtpServer(outputStream, inputStream); close(ftpClient,outputStream, inputStream);/关闭 catch(Exception e) e.printStackTrace(); /*从Ftp服务器上下载文件*/ public void downloadFormFtp(String serverUrl, String userName, String passWord, String downLoadFile, String serverPath) FtpClient ftpClient = null; try ftpClient = new FtpClient(); boolean isOpenSuccess = loginToFtpServer(ftpClient, serverUrl, userName, passWord); if (isOpenSuccess) /以下几步顺序不能错 /进入服务器的指定目录 ftpClient.cd(serverPath); OutputStream outputStream = new FileOutputStream(new File(E:test.csv); InputStream inputStream = getFtpClientInputStream(ftpClient, downLoadFile); writeToLocal(inputStream, outputStream); close(ftpClient,outputStream, inputStream);/关闭 catch (Exception e) /* 登录到Ftp服务器 */ public boolean loginToFtpServer(FtpClient ftpClient,String serverUrl, String userName, String passWord) try ftpClient.openServer(serverUrl); ftpClient.login(userName, passWord); return true; catch (IOException e) System.out.println(Ftp 客户端打开失败); return false; /* 得到ftp客户端的输出流 */ public OutputStream getFtpClientOutputStream(FtpClient ftpClient, String uploadFile) throws IOException ftpClient.binary(); /因为已经进入到了服务的目录,只要在目录下建一个文件就行,所以只要文件名,不要路径 File file = new File(uploadFile); return ftpClient.put(file.getName(); /* 得到ftp客户端的输出流 */ public InputStream getFtpClientInputStream(FtpClient ftpClient, String downLoadFile) throws IOException ftpClient.binary(); /因为已经进入到了服务的目录,只要在目录下建一个文件就行,所以只要文件名,不要路径 File file = new File(downLoadFile); return ftpClient.get(file.getName(); /* 得到本地文件的输入流 */ public InputStream getLocalFileInputStream(String fileName) throws FileNotFoundException return new FileInputStream(new File(fileName); /* 向ftp服务器写入文件 */ public void writeToFtpServer(OutputStream outputStream, InputStream inputStream) throws IOException byte bytes = new byte1024; while(inputStream.read(bytes) != -1) outputStream.write(bytes,0,bytes.length); outputStream.flush(); /*下载文件到本地*/ public void writeToLocal(InputStream inputStream, OutputStream outputStream) throws IOException byte bytes = new byte1024; while(inputStream.read(bytes) != -1) outputStream.write(bytes,0,bytes.length); /* 关闭 */ public void close(FtpClient ftpClient, OutputStream outputStream, InputStream inputStream) throws IOException if(inputStream != null) inputStream.close(); if(outputStream != null) outputStream.close(); if(ftpClient != null) ftpClient.closeServer(); OAFUPLOAD.java/*=+ | Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA | | All rights reserved. | +=+ | HISTORY | +=*/package oracle.apps.ak.uploadfile.webui;import mon.VersionInfo;import oracle.apps.fnd.framework.OAException;import oracle.apps.fnd.framework.webui.OAControllerImpl;import oracle.apps.fnd.framework.webui.OAPageContext;import oracle.apps.fnd.framework.webui.beans.OAWebBean; /* * Controller for . */public class UploadCO extends OAControllerImpl public static final String RCS_ID=$Header$; public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion(RCS_ID, %packagename%); /* * Layout and page setup logic for a region. * param pageContext the current OA page context * param webBean the web bean corresponding to the region */ public void processRequest(OAPageContext pageContext, OAWebBean webBean) cessRequest(pageContext, webBean); /* * Procedure to handle form submissions for form elements in * a region. * param pageContext the current OA page context * param webBean the web bean corresponding to the region */ public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) cessFormRequest(pageContext, webBean); if (pageContext
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度汽车零部件维修与再制造产业合作合同
- 2025高端医疗设备租赁及全面性能检测服务协议
- 2025年度星际旅行主题科幻小说改编电视剧本委托合同
- 2025年生物技术专利权质押投资合作开发协议
- 2025年定制化办公复印租赁及高效打印耗材配套服务协议
- 2025年绿色建筑一体化设计及环保材料采购合作协议
- 2025年文化旅游终止合同证明书:历史文化名城景区改造合同
- 2025年农家乐景区运营管理及旅游服务全面合作协议
- 2025年新型专利技术授权及转让服务合同范本
- 2025年度产学研一体化跟岗实习实训基地共建合同
- 0.4kV不停电作业资质认证练习试题及答案
- 高一离子方程式书写专题训练及答案
- 北京市海淀区2020-2021学年七年级下学期期末历史试题(答案)
- 新媒体运营PPT完整全套教学课件
- 渝20TJ11 浮筑楼板隔声保温系统构造 难燃型改性聚乙烯复合卷材(蜂窝型)DJBT 50-143
- 2023年内蒙古呼伦贝尔农垦拉布大林、上库力、三河、苏沁农牧场有限公司招聘笔试题库及答案解析
- 节日期间纪检监督检查记录表
- GB/T 311.1-2012绝缘配合第1部分:定义、原则和规则
- (完整word)600习题《工会基础知识试题及答案》2020.1.6
- 中医药法宣讲余课件
- 富士康科技集团劳保用品采购
评论
0/150
提交评论