服务器端java struts2的phonegap上传
来源:互联网 发布:淘宝地址转换 编辑:程序博客网 时间:2024/05/22 13:50
前端:
//voiceURI 所要上传的文件本地URI var options = new FileUploadOptions(); options.fileKey="upload"; options.fileName=voiceURI.substr(voiceURI.lastIndexOf('/')+1); console.log(options.fileName+" ~~~ "+voiceURI); options.mimeType="multipart/form-data";//设置为这种类型,则和form表单提交一样 options.chunkedMode = false; //必须 不知道什么原因 /**var params = new Object(); params.value1 = "test"; params.value2 = "param"; options.params = params; */ var ft = new FileTransfer(); //RecordVoice.uploadAction struts2 action ft.upload(voiceURI, RecordVoice.uploadAction, function(r){ console.log("Code = " + r.responseCode); console.log("Response = " + r.response); console.log("Sent = " + r.bytesSent); console.log("voiceNetPath = " + voiceNetPath); }, function(error){ alert("An error has occurred: Code = " = error.code); }, options);
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class UploadAction extends ActionSupport{ private String title; private File upload; //File变量名 必须与options.fileKey的值相同 private String uploadContentType;//变量名必须 File的变量名+ContentType private String uploadFileName;//变量名必须 File的变量名+FileNameprivate String allowTypes; // 接受依赖注入的属性 private String savePath; // 接受依赖注入的方法 public void setSavePath(String value) { this.savePath = value; } private String getSavePath(){// return ServletActionContext.getServletContext().getRealPath(savePath); return "D:\\apache-tomcat-6.0.29\\webapps\\ROOT\\HIMSSVOICE"; } public void setTitle(String title) { this.title = title; } public void setUpload(File upload) { this.upload = upload; } public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String getTitle() { return (this.title); } public File getUpload() { return (this.upload); } public String getUploadContentType() { return (this.uploadContentType); } public String getUploadFileName() { return (this.uploadFileName); } @Override public String execute() { System.out.println("开始上传单个文件---"); System.out.println("地-址:"+getSavePath()); System.out.println("==========" + getUploadFileName()); System.out.println("==========" + getUploadContentType()); System.out.println("==========" + getUpload()); System.out.println("=====0====="+allowTypes); // 判断是否允许上传// String filterResult = filterType(this.getAllowTypes().split(","));// if (filterResult != null) {// ActionContext.getContext().put("typeError","您要上传的文件类型不正确");// return filterResult;// } System.out.println("=====1====="); // 以服务器的文件保存地址和原文件名建立上传文件输出流 FileOutputStream fos;try { File savefile = new File(getSavePath() + "\\"+ getUploadFileName()); if (!savefile.getParentFile().exists()){ savefile.getParentFile().mkdirs(); } fos = new FileOutputStream(getSavePath() + "\\" + getUploadFileName()); FileInputStream fis = new FileInputStream(getUpload()); byte[] buffer = new byte[1024]; int len = 0; while ((len = fis.read(buffer)) > 0) { fos.write(buffer, 0, len); }} catch (Exception e) {e.printStackTrace();} return SUCCESS; } public String filterType(String[] types) { String fileType = this.getUploadContentType(); for (String type : types) { if (type.equals(fileType)) { return null; } } return INPUT; } public String getAllowTypes() { return allowTypes; } public void setAllowTypes(String allowTypes) { this.allowTypes = allowTypes; }}
- 服务器端java struts2的phonegap上传
- struts2文件上传(服务器端)
- java web获取上传的文件在服务器端的路径
- 【游戏后端】Java服务器端检测客户端上传来的数据
- PhoneGap 文件上传(Java 后台代码)
- phonegap(cordova)文件上传(Java,PHP)
- struts2服务器端的表单验证
- FCKeditor.java+Struts2的上传文件配置
- phonegap 上传任意格式文件的js代码
- java struts2 文件上传
- Java 文件分块上传服务器端源代码
- Java 文件分块上传服务器端源代码
- Java 文件分块上传服务器端源代码
- Java 文件分块上传服务器端源代码
- Java中上传文件到服务器端
- [Struts2]Struts2的文件上传
- Struts2服务器端的验证(验证框架)
- Struts2的文件上传
- 拷问Unity:开发U3D游戏要思考的问题
- Android SeekBar设置为垂直的布局
- android 文件读写概述
- PHP获取用户真实 IP , 淘宝IP接口获得ip地理位置
- FARPOINT 常见用法
- 服务器端java struts2的phonegap上传
- 简析SynchronousQueue,LinkedBlockingQueue,ArrayBlockingQueue
- Zend Studio 9.0.0注册码与汉化方法
- 斯蒂芬森的
- scrum经典管理工具:白板和即时贴
- 8,手动内存管理
- Unity3D 游戏贴图(法线贴图,漫反射贴图,高光贴图)
- Weblogic集群配置过程
- cocos2d-x系列笔记(9.1)---浅谈cocos2d-x使用函数指针实现委托(上)---通过c#代码理解委托