form.js提交表单同步上传图片

		String pptpath = request.getRealPath("scwd");//路径
		//关键点,关于数组类型,struts会保存为Hashtable  
		Hashtable fileh = form.getMultipartRequestHandler().getFileElements();  		
		String dypptList="";
		String realpptList="";		
		for (Iterator it = fileh.keySet().iterator(); it.hasNext();)  {  
		   String key = (String) it.next();  
		   //得到附件,jsp页面中表单域的名称不能相同,否则只能得到最后一个附件  
		   FormFile ff = (FormFile) fileh.get(key);     
		   String dyppt =   ff.getFileName();  	 //获取上传文件名
		   if (!"".equals(dyppt)&&null!=dyppt) {
			   if ((!fileLastName(dyppt).equals("jpg"))&&(!fileLastName(dyppt).equals("JPG"))&&(!fileLastName(dyppt).equals("bmp"))&&(!fileLastName(dyppt).equals("BMP")))
			    {
				   JsonUtil.outInfo(response, "请选择jpg或bmp格式图片", true);
					return;
			    }	
			   String sjc = doDate();
			   dypptList+=dyppt+";";
			   realpptList+=sjc+oper_id+dyppt.substring(dyppt.indexOf("."), dyppt.length())+";";
			   	//多文件上传
				if(null!=t.getDyppt()&&!"".equals(t.getDyppt())) t.setDyppt(t.getDyppt()+";"+dyppt);//文件名称
				else t.setDyppt(dyppt);//文件名称
				if(null!=t.getRealppt()&&!"".equals(t.getRealppt())) t.setRealppt(t.getRealppt()+";"+sjc+oper_id+dyppt.substring(dyppt.indexOf("."), dyppt.length()));//真实文件名称
				else t.setRealppt(sjc+oper_id+dyppt.substring(dyppt.indexOf("."), dyppt.length()));//真实文件名称
				
				t.setPptpath(pptpath);//路径
				//进行文档操作
			   	if(ff!=null&&!StrUtil.strnull(ff.getFileName()).equals("")){
					try{
						InputStream stream = ff.getInputStream();
						OutputStream bos = new FileOutputStream(pptpath + "/"+ sjc+oper_id+dyppt.substring(dyppt.indexOf("."), dyppt.length()));
						System.out.println(pptpath + "/"+ sjc+oper_id+dyppt.substring(dyppt.indexOf("."), dyppt.length()));
						int bytesRead = 0;
						byte[] buffer = new byte[8192];
						while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
							bos.write(buffer, 0, bytesRead);
						}
						bos.close();
						stream.close();
					}catch(Exception e){
						e.printStackTrace();
						au.setInfo(au.getInfo()+"文档操作错误:"+e.getMessage());				
					}
					request.setAttribute("sheet_no", sheet_no);
					request.setAttribute("msg", au.getFlag());
					//request.setAttribute("info", au.getInfo().toString());
				}
		   }else{
			   continue;
		   }
		
		}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值