网站建设资讯

NEWS

网站建设资讯

关于使用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" />

<% String userid=(String)request.getAttribute("userid");

  String id=(String)request.getAttribute("id");

%>

<%-- 编辑印章信息--%>

id="form1" name="form1">

印章编号:

印章类型:

印章刻文:

使用年限:

数字证书:

type="file" />

印章文件:

type="file" />

开始日期:

结束日期:

持章人姓名:

手机号码:

邮箱:

key:

持章人***:

上传***:

证书类型:

>

/>

/>

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://cdweb.net/article/goedgc.html