easyui SWFUpload
业务背景:实现一个用药人的增加功能,用药人信息中包含附件。如题所示,主要讨论easyui上传的实现。
jsp页面代码(弹出框),一个简单的增加页面
div id=addMedicationDlg class=easyui-window closed=true title= iconCls=icon-add style=width350px; height390px;text-aligncenter; background #fafafa;
div class=easyui-layout fit=true
div region=center border=false style=background#fff;border1px solid #ccc;padding-left 20px;
input type=hidden id=mid name=mid
form id=addMedicationForm method=POST
input type=hidden id=sex
table border=0 class=queryTable style=margin-bottom 0px tr
td class=queryTitle附件:td
td class=queryContent
input class=inputText type=text id=urlkeywords!-- 放入的是附件路径--
input type=hidden id=goodsNo name=goodsNo !-- 附件列表 --
input type=hidden class=inputText id=swfText
span id=keyWordImportBtnspan!--上传按钮--
td
td
<!--显示进度条-->
div id=fsUploadProgressdiv
div id=divStatus style=display none;div
input id=btnCancel type=buttondisabled=disabled style=display none
td
tr
table
table border=0 class=queryTable style=margin-bottom 0px id=fileIdTlb
tbody
tbody
table
form
div
div region=south border=false style=text-aligncenter;height30px;line-height30px;
a class=easyui-linkbutton iconCls=icon-ok href=javascriptvoid(0) onclick=doPostData()确定a
a class=easyui-linkbutton iconCls=icon-cancel href=javascriptvoid(0) onclick=cancelPostData('addMedicationDlg')取消a
div
div
div
js文件代码
/**
* 打开修改&增加用药人窗口
*/
function doModifyMedication (mid){
//弹出修改&增加用药人窗口
$('#addMedicationDlg').window({
title '修改用药人',
iconCls 'icon-edit',
width750,
height550,
left250,
modal true,
shadow true,
collapsible false,
minimizable false,
maximizable false
});
$(#addMedicationDlg).show();
$('#addMedicationDlg').window('move',{top20});
$('#addMedicationDlg').window('open');
//这一步很关键,初始化上传操作
initSWFUpload({
upload_url appPath + pagequeryMedicationkeyWordImport+generateMixed(6),
post_params{},
button_placeholder_id keyWordImportBtn,
upload_start_handler uploadStartFn,
upload_success_handler importOk,
file_types .png;.jpg;.gif,
debugfalse,
custom_settings {
progressTarget fsUploadProgress,
cancelButtonId btnCancel
}
});
}
/**
*保存提交
*/
function doPostData(){
//序列化表单
var userinfo = $('#addMedicationForm').serialize();
doAjax({
urlappPath + 'pagequeryMedicationaddMedication'+ memberId,
type'POST',
datauserinfo,
successfunction(data){
if(data ==true){
$.messager.alert('提示信息','保存成功','info');
$('#selectMedicineManDlg').window('close');
cancelPostData('addMedicationDlg');
lookMedication(memberId);
}else{
$.messager.alert('提示信息','抱歉,操作未能完成,'+data,'error');
}
},
errorfunction(XMLHttpRequest, textStatus, errorThrown){
$.messager.alert('提示信息','抱歉,操作未能完成,'+textStatus,'error');
}
});
}
/**
*取消提交
*@param dlg
*/
function cancelPostData(dlg){
$('#'+dlg).window('close');
}
后台java代码
/**
* 保存文件(在文件初始化的时候执行)
*
* @param request
* @param response
* @param uploadFile
* @throws Exception
*/
@RequestMapping(value = "/keyWordImport")
public Object keyWordImport(HttpServletRequest request,
HttpServletResponse response,
@RequestParam("uploadFile") MultipartFile f) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HashMap<String, Object> map = new HashMap<String, Object>();
String type = "" ;
String splitKey = ""; //---设置字符集
try {
request.setCharacterEncoding("utf-8");
} catch (Exception e) {
e.printStackTrace();
}
response.setCharacterEncoding("utf-8"); if (null != request.getParameter("splitKey")){
splitKey = request.getParameter("splitKey");
} //---获取文件名称、文件后缀名称以及生成新名称
String oldFileName = f.getOriginalFilename();
if(null!=oldFileName && oldFileName.contains(".")){
type = oldFileName.substring(oldFileName.lastIndexOf(".")).toLowerCase();
}
String newFileName =oldFileName.substring(0,oldFileName.lastIndexOf("."))+String.valueOf(System.currentTimeMillis())+type;
try {
// ---获取文件保存目录名称 String saveFolder = request.getSession().getServletContext()
.getRealPath("upload")
+ "/" + "otcFolder"; String newFileNamePath = "/upload/otcFolder/"+ newFileName;
map.put("newFileName", newFileNamePath); // ---上传
Map<String, Object> res = uploadService.doUpload(saveFolder,
f.getBytes(), newFileName, splitKey, "otcFolder");
// ---返回值
if (0 == (Integer) res.get("error")) {
request.setAttribute("res", "success");
response.getWriter().write(org.json.simple.JSONObject.toJSONString(map));
} else {
request.setAttribute("res",
"err : " + (String) res.get("message"));
}
} catch (Exception e) {
request.setAttribute("res", "err : " + e.getMessage());
logger.error("upload failed in action " + e.getMessage());
}
return null;
}
//保存用药人新增数据
@RequestMapping(value="/addMedication/{memberId}")
@ResponseBody
public String addMedication (HttpServletRequest request ,@PathVariable Long memberId,Medication medication) throws Exception {
String fileList = medication.getGoodsNo();
String temps [] =fileList.split(",");
List<MedicationMemberFile> list =new ArrayList<MedicationMemberFile>();
for (int i = 0 ;i<temps.length ; i++){
MedicationMemberFile medicationMemberFile = new MedicationMemberFile();
if (temps[i].trim().length() >0 || temps[i].trim() != null){
medicationMemberFile.setFilePath(temps[i]);
list.add(medicationMemberFile);
}
}
medication.setMedicationMemberFile(list);
medication.setMemberId(memberId);
String result ="";
String resultDataRecord = SOAJsonClient.sendMsgToOtc(OtcJsonCodeRelation.JsonAssignedDetailsTasksService_setAddMedication,JSON.toJSONString(medication) );
JSONObject objectRecord = JSONObject.fromObject(resultDataRecord);
String objectstate=String.valueOf(objectRecord.get("state"));
if(objectstate.trim().length() >0 && objectstate.equals("0")){
result ="true";
}
return result;
}
easyui SWFUpload的更多相关文章
- easyUI + swfupload 多附件上传功能
public void UPLOADFILED() { Date dt = new Date(System.currentTimeMillis()); SimpleDateFormat sdf = n ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(32)-swfupload多文件上传[附源码]
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(32)-swfupload多文件上传[附源码] 文件上传这东西说到底有时候很痛,原来的asp.net服务器 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(32)-swfupload多文件上传[附源码]
系列目录 文件上传这东西说到底有时候很痛,原来的asp.net服务器控件提供了很简单的上传,但是有回传,还没有进度条提示.这次我们演示利用swfupload多文件上传,项目上文件上传是比不可少的,大家 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 任务调度系统界面 http: ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(56)-插件---单文件上传与easyui使用fancybox
系列目录 https://yunpan.cn/cZVeSJ33XSHKZ 访问密码 0fc2 今天整合lightbox插件Fancybox1.3.4,发现1.3.4版本太老了.而目前easyui 1 ...
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统
开篇:从50开始系统已经由MVC4+EF5+UNITY2.X+Quartz 2.0+easyui 1.3.4无缝接入 MVC5+EF6+Unity4.x+Quartz 2.3 +easyui 1.4. ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(36)-文章发布系统③-kindeditor使用
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(36)-文章发布系统③-kindeditor使用 我相信目前国内富文本编辑器中KindEditor 属于前 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(转)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 日程管理 http://ww ...
- ASP.NET MVC下使用SWFUpload完成剪切头像功能
首先介绍SWFUpload组件 SWFUpload是一个客户端文件上传工具,最初由Vinterwebb.se开发,它通过整合Flash与JavaScript技术 为WEB开发者提供了一个具有丰富功能继 ...
随机推荐
- windows下安装storm1.1.0并启动
64位windows安装storm前需要先搞定zookeeper和python,所以下面我们3步走: 一.zookeeper 1.上https://zookeeper.apache.org/点击下方d ...
- nginx.conf几个示例
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
- Idea 如何设置微软雅黑等其它字体
使用过idea的同学都知道,idea的功能相对于explise来说,功能太强大了啊~个人感觉,idea真心挺智能的.但是,这里有一个小瑕疵,就是能够设置的字体,有限! 对于用惯了 微软雅黑 字体的人, ...
- ARM-Linux移植之(三)——init进程启动流程分析
我们通常使用Busybox来构建根文件系统的必要的应用程序.Busybox通过传入的参数来决定执行何种操作.当init进程启动时,实际上调用的是Busybox的init_main()函数,下面我们来分 ...
- babel-polyfill使用简介
babel-polyfill介绍 简介 使用这个插件你可随心所欲的使用es6甚至更高版本的方法,这个插件自动转码 安装 这个插件必须在你的源码运行之前运行,所以必须安装成dependency npm ...
- flask系列七之cookie和session
该部分参考链接: http://blog.csdn.net/qq_28877125/article/details/77677890 http://blog.csdn.net/qq_28877125/ ...
- Java面向对象-方法的定义及简单使用
Java面向对象之方法 方法是对象的一部分,也称为行为: 先来一个简单实例: package com.java1234.chap03.sec03; public class Person { void ...
- Halcon学习之一:查询图像参数
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.get_grayval ( Image : : Row, Column : Grayval ) 计算Image图像中坐标为(Row,Colum ...
- ___pInvalidArgHandler already defined in LIBCMTD.lib(invarg.obj)
vs2013编译项目时出错,网上很多的解决方案全都是垃圾,根本不能用 不过也有不是垃圾的,就是下面这个: 关于采用静态链接编译生成EXE库函数重复定义问题 看了好多关于类似LIBCMT.lib(inv ...
- Libevent使用例子,从简单到复杂
转载请注明出处:http://blog.csdn.net/luotuo44/article/details/39670221 本文从简单到复杂,展示如何使用libevent.网上的许多例子都是只有服务 ...