业务背景:实现一个用药人的增加功能,用药人信息中包含附件。如题所示,主要讨论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的更多相关文章

  1. easyUI + swfupload 多附件上传功能

    public void UPLOADFILED() { Date dt = new Date(System.currentTimeMillis()); SimpleDateFormat sdf = n ...

  2. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(32)-swfupload多文件上传[附源码]

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(32)-swfupload多文件上传[附源码] 文件上传这东西说到底有时候很痛,原来的asp.net服务器 ...

  3. ASP.NET MVC5+EF6+EasyUI 后台管理系统(32)-swfupload多文件上传[附源码]

    系列目录 文件上传这东西说到底有时候很痛,原来的asp.net服务器控件提供了很简单的上传,但是有回传,还没有进度条提示.这次我们演示利用swfupload多文件上传,项目上文件上传是比不可少的,大家 ...

  4. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库  您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB  升级后界面效果如下: 任务调度系统界面 http: ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(56)-插件---单文件上传与easyui使用fancybox

    系列目录 https://yunpan.cn/cZVeSJ33XSHKZ  访问密码 0fc2 今天整合lightbox插件Fancybox1.3.4,发现1.3.4版本太老了.而目前easyui 1 ...

  6. 构建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. ...

  7. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(36)-文章发布系统③-kindeditor使用

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(36)-文章发布系统③-kindeditor使用 我相信目前国内富文本编辑器中KindEditor 属于前 ...

  8. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(转)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 日程管理   http://ww ...

  9. ASP.NET MVC下使用SWFUpload完成剪切头像功能

    首先介绍SWFUpload组件 SWFUpload是一个客户端文件上传工具,最初由Vinterwebb.se开发,它通过整合Flash与JavaScript技术 为WEB开发者提供了一个具有丰富功能继 ...

随机推荐

  1. (转)IE=EmulateIE7 标签的作用

    本文转载自:http://www.cnblogs.com/0000/archive/2009/11/01/1593851.html 对于 Web 开发人员来说,文本兼容性是一个要考虑的重要问题.Win ...

  2. Mybatis拦截器介绍及分页插件

    1.1    目录 1.1 目录 1.2 前言 1.3 Interceptor接口 1.4 注册拦截器 1.5 Mybatis可拦截的方法 1.6 利用拦截器进行分页 1.2     前言 拦截器的一 ...

  3. PHPCMS分页原理

    调用很方便,使用listinfo方法,如果小于1页不会返回分页字符串 $page = $_GET['page'] ? intval($_GET['page']) : '1'; $products = ...

  4. php中的move_uploaded_file

    1.定义和用法 move_uploaded_file() 函数将上传的文件移动到新位置. 若成功,则返回 true,否则返回 false. 2.语法 move_uploaded_file(file,n ...

  5. 第四章 Javac编译原理

    4.1 Javac是什么 是一种编译器,将JAVA源代码(.java文件)语言先转化成JVM能够识别的一种语言(.class文件),然后由JVM将JVM语言再转化成当前机器可以识别的机器语言. 4.2 ...

  6. USB接线图

    一.简介 通用串行总线(英文:Universal Serial Bus,简称USB)是连接外部装置的一个串口汇流排标准,在计算机上使用广泛,但也可以用在机顶盒和游戏机上,补充标准On-The-Go( ...

  7. DFT的理解

    在以前学习的离散傅立叶变换(DFT),总是不能理解只是知道公式 X(k) = Σx(n) * WNnk    ,也不知道如何得来的. 现在可以聊聊了,因为最近在使用MATLAB实际的操作了所以比以前了 ...

  8. temp4

  9. windows网络服务之配置网络负载均衡(NLB)群集

    O首页51CTO博客我的博客 搜索 每日博报 社区:学院论坛博客下载更多            登录注册 家园 学院 博客 论坛 下载 自测 门诊 周刊 读书 技术圈 曾垂鑫的技术专栏 http:// ...

  10. MySQL备份还原之三使用xtrabackup

    1 xtrabackup安装 1)解压源码包 tar -xzvf percona-xtrabackup-2.1.7.tar.gz 2)安装perl环境(DBI/DBD) yum install per ...