ADF 上传文件到服务器 方法之一
来源:互联网 发布:javaweb报销系统源码 编辑:程序博客网 时间:2024/04/29 22:05
一、前台页面实现
<afh:body> <af:form id="form" usesUpload="true"> <af:panelForm inlineStyle="border-style:solid; border-color:rgb(0,0,0); border-width:1.0pt; "> <afh:tableLayout cellPadding="1" borderWidth="0" halign="center" cellSpacing="0" width="750px"> <afh:rowLayout inlineStyle="height:20px;"/> <afh:rowLayout> <afh:cellFormat halign="center"> <af:panelHorizontal> <af:outputLabel value="#{res['BIDMANAGE.UPLOAD_FILE_SELECT']}"/> <af:objectSpacer width="8"/> <af:inputFile inlineStyle="width:450px;" id="file" binding="#{bidBatchFileUploadBean.upFile}"/> </af:panelHorizontal> </afh:cellFormat> </afh:rowLayout> <afh:rowLayout> <afh:cellFormat halign="center" height="50px" valign="middle"> <af:panelHorizontal> <af:commandButton text="#{res['UPLOAD']}" onclick="saveFile();" action="#{bidBatchFileUploadBean.uploadFileButton}"/> <af:objectSpacer width="20"/> <af:commandButton text="#{res['BIDMANAGE.RETURN']}" action="#{bidBatchFileUploadBean.returnBidSectionEdit}"/> </af:panelHorizontal> </afh:cellFormat> </afh:rowLayout> </afh:tableLayout> </af:panelForm> </af:form> </afh:body>
注意页面中form设置属性 usesUpload="true"
效果如下:
二、java类种方法uploadFileButton实现
public String uploadFileButton() { //上传的附件名称 String mainDocName = ""; //获取上传的文件 System.out.println("00000000000000000proName="+proName ); UploadedFile file = (UploadedFile)this.getUpFile().getValue(); System.out.println("file="+file); if (file != null) { //检查文件类型 mainDocName = file.getFilename(); System.out.println("mainDocName=========>" + mainDocName); long fileSize = file.getLength() / 1024; System.out.println("文件大小:" + fileSize + "KB"); if (fileSize > 81920) { this.showInfoMessage("文件过大!"); return null; } //文件上传路径 Properties pros = new Properties(); try { pros.load(this.getClass().getClassLoader().getResourceAsStream("test/bean/config.properties")); } catch (Exception e) { } String path = pros.getProperty("path"); System.out.println("path " + path); String dirFlag = System.getProperty("file.separator"); //自动匹配操作系统文件路径 String saveDirectory = ""; File dir = new File(saveDirectory); if(!dir.isDirectory()) dir.mkdirs(); InputStream birdIn; FileOutputStream birdOut; //获取系统当前时间 java.text.SimpleDateFormat date = new java.text.SimpleDateFormat("yyyyMMddHHmmssSS"); String currentTimeMillis = date.format(new Date(System.currentTimeMillis())); //随机数 java.util.Random rand = new java.util.Random(); int iValue = rand.nextInt(); String t1_fname = mainDocName.substring(0,mainDocName.lastIndexOf(".")); String t2_fname = mainDocName.substring(mainDocName.lastIndexOf(".")); String mainName=""; mainName = t1_fname + "_"+currentTimeMillis + t2_fname; byte[] bytes1 = UrlBase64.encode((path+dirFlag).getBytes()); byte[] bytes2 = UrlBase64.encode(mainName.getBytes()); String encodeNewFilePath = new String(bytes1); String encodeNewFileName = new String(bytes2); String address = path + mainName; System.out.println("address===="+address); String url =path + mainDocName; try{ birdOut = new FileOutputStream(address); birdIn = file.getInputStream(); for (int bytes = 0; bytes < file.getLength(); bytes++) { birdOut.write(birdIn.read()); } birdIn.close(); birdOut.close(); }catch(Exception e){ StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String result = sw.toString(); if (result.indexOf("ORA-20017:") > 0) { this.showInfoMessage(MessageCommon.getFlexMessage(e)); } else { this.showWarnMessage(result); System.out.println(result); } } } return null; }
0 0
- ADF 上传文件到服务器 方法之一
- 使用ADF上传文件到服务器
- adf中用inputFile上传文件到weblogic 方法1
- 上传文件到服务器方式之一:使用InputFile的ValueChangeListener
- PHP:上传文件到服务器的方法
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- ADF实现文件上传
- ADF实现文件上传
- 如何使用git 生成patch
- Swift Moya
- SWIG,C/C++类库与Java,Python等泛高阶语言的万能粘合剂
- iOS 剪切圆形图片
- hazelcast学习笔记---sharding与cluster
- ADF 上传文件到服务器 方法之一
- 字节 和 位
- bat运行runnable jar file
- Git 在实际项目中的使用
- IE浏览器兼容问题
- C#中Monitor和Lock以及区别
- linux 将更新的文件copy到sshfs挂载主机,监测sshfs,不存在则启动
- 养护卵巢的十大食物推荐!(值得收藏)
- Android仿大众点评