关于使用ajaxfileupload来上传file文件的若干总结
最近在做文件上传的时候看到ajaxfileupload来做文件的上传,感觉很有意思。记录下来方便以后在做相关的功能是自己查阅。
武鸣网站建设公司成都创新互联,武鸣网站设计制作,有大型网站制作公司丰富经验。已为武鸣上千家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的武鸣做网站的公司定做!
jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
rel="stylesheet" type="text/css" />
* {
font-size: 12px;
}
$(function() {
$("#start").ligerDateEditor();
$("#end").ligerDateEditor();
});
function saveSeal() {
var beginDate = document.getElementById("start").value;
var endDate = document.getElementById("end").value;
if (beginDate != "" && endDate != "") {
if (beginDate > endDate) {
$.ligerDialog.warn("开始日期必须小于结束日期");
return false;
}
}
$.ajax( {
type : 'post',
async : false,
url : 'saveEditSeal_sealManager.action',
data : $('#form1').serialize(),
success : function(jsons) {
if (!jsons) {
$.ligerDialog.error("操作失败");
} else {
$.ajaxFileUpload( {
url : "saveEditSealFile_sealManager.action?id="
+ $("#sealNO").val(),
secureuri : false,
fileElementId : [ 'sealfile', 'signfile', 'idfile' ],
dataType : 'json',
/**success : function(data,status){
alert(data);
}**/
success : function(json) {
if (json == true) {
$.ligerDialog.warn("操作成功", function(value) {
if (value) {
window.parent.location.reload();
//window.location.reload();
}
});
} else {
$.ligerDialog.warn("操作失败", function(value) {
if (value) {
window.parent.location.reload();
}
});
}
}
});
}
}
})
}
/**
* 取消按钮事件
*/
function cancel() {
//alert("kkk");
//$(".l-dialog-close").close();
parent.$.ligerDialog.close();
parent.$(".l-dialog,.l-window-mask").remove();//只隐藏遮罩层
}
body {
padding: 10px;
}
.showTit {
background: url(../../lib/ligerUI/skins/icons/communication.gif);
background-repeat: no-repeat;
line-height: 25px;
padding-left: 25px;
font-weight: bold;
border-bottom: 1px solid #ccc;
}
.showTab {
line-height: 30px;
text-align: left;
}
<% String userid=(String)request.getAttribute("userid");
String id=(String)request.getAttribute("id");
%>
<%-- 编辑印章信息--%>
action层只要代码代码
public class SealManagerAction{
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(SealManagerAction.class);
private ISealManagerService sealManagerService;
//private PageBean pageBean = new PageBean();
//private MinicollectSeals minicollectSeals;
private ISealUserService sealUserService;
private ISealinfoService sealinfoService;
private File sealfile;// 印章文件
private String sealfileFileName;
private File signfile;// 数字签名证书
private String signfileFileName;
private File idfile;// 个人***
private String idfileFileName;
private Sealinfo sealinfo;
private Sealuser sealuser;
..............
public void saveEditSeal() {
try {
Sealinfo sealinfo1 = new Sealinfo();
User user = (User) request.getSession().getAttribute("loginUser");
Sealinfo sealinfo2=sealinfoService.findSealinfoByInventory(sealinfo.getInventory());
if (sealinfo2!=null) {
sealinfo2.setUserid(sealinfo.getUserid());
sealinfo2.setApplytype(sealinfo.getApplytype());
sealinfo2.setCertype(sealinfo.getCertype());
sealinfo2.setContent(sealinfo.getContent());
sealinfo2.setEmail(sealinfo.getEmail());
sealinfo2.setEnd(sealinfo.getEnd());
sealinfo2.setIdno(sealinfo.getIdno());
sealinfo2.setIndate(sealinfo.getIndate());
sealinfo2.setPhone(sealinfo.getPhone());
sealinfo2.setSealno(sealinfo.getSealno());
sealinfo2.setSealusername(sealinfo.getSealusername());
sealinfo2.setStart(sealinfo.getStart());
sealinfo2.setType(sealinfo.getType());
sealinfo2.setUsbkey(sealinfo.getUsbkey());
sealinfo2.setInventory(sealinfo.getInventory());
sealinfoService.addSealinfo(sealinfo2);
} else {
sealinfo1.setUserid(sealinfo.getUserid());
sealinfo1.setApplytype(sealinfo.getApplytype());
// sealinfo1.setCerpath(cerpath)
sealinfo1.setCertype(sealinfo.getCertype());
sealinfo1.setContent(sealinfo.getContent());
sealinfo1.setEmail(sealinfo.getEmail());
sealinfo1.setEnd(sealinfo.getEnd());
sealinfo1.setIdno(sealinfo.getIdno());
sealinfo1.setIndate(sealinfo.getIndate());
sealinfo1.setPhone(sealinfo.getPhone());
sealinfo1.setSealno(sealinfo.getSealno());
sealinfo1.setSealusername(sealinfo.getSealusername());
sealinfo1.setStart(sealinfo.getStart());
sealinfo1.setType(sealinfo.getType());
sealinfo1.setUsbkey(sealinfo.getUsbkey());
sealinfo1.setInventory(sealinfo.getInventory());
sealinfoService.addSealinfo(sealinfo1);
}
/*
* String id=sealinfo.getId(); Gson gson = new
* GsonBuilder().setDateFormat("yyyy-MM-dd").create(); String
* outString=gson.toJson(sealinfo);
*/
response.getWriter().print(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage());
}
}
public void saveEditSealFile() {
String idno = request.getParameter("id");
String sealpath = UploadConfigurationRead.getInstance().getConfigItem(
"uploadSealFilePath").trim();
String signpath = UploadConfigurationRead.getInstance().getConfigItem(
"uploadSignFilePath").trim();
String idpath = UploadConfigurationRead.getInstance().getConfigItem(
"uploadIdFilePath").trim();
try {
Sealinfo sealinfo = sealinfoService.findSealinfo(idno);
//Sealuser sealuser = sealinfo.getSealuser();
if(sealfile!=null&&sealfile.length()>0){
File xmlFile = uploadXmlFile(sealpath, sealinfo.getId(), sealfile);
sealpath = sealXMLParse(xmlFile,sealpath,sealinfo.getId());
// if(xmlFile.exists()){
// xmlFile.delete();
// }
sealinfo.setSealpath(sealpath);
}
if(signfile!=null&&signfile.length()>0){
signpath = uploadFile(signpath, sealinfo.getSealno()
+ signfileFileName.substring(signfileFileName.lastIndexOf(".")), signfile);
sealinfo.setCerpath(signpath);
}
if(idfile!=null&&idfile.length()>0){
idpath = uploadFile(idpath, sealinfo.getSealno()
+ idfileFileName.substring(idfileFileName.lastIndexOf(".")), idfile);
sealinfo.setIdpath(idpath);
}
//sealUserService.save(sealuser);
sealinfoService.addSealinfo(sealinfo);
response.getWriter().print(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage());
}
}
public String uploadFile(String directory, String filename, File file)
throws IOException {
String fiePath = directory + File.separator + filename;
File target = new File(fiePath);
FileUtils.copyFile(file, target);
return fiePath;
}
public File uploadXmlFile(String directory,String filename,File file) throws IOException{
File target = new File(directory + File.separator + filename + ".xml");
FileUtils.copyFile(file, target);
return target;
}
}
网站题目:关于使用ajaxfileupload来上传file文件的若干总结
当前路径:http://azwzsj.com/article/goedgc.html