模板上传及下载

模板上传

jsp页面代码如下:

<div id="select_condition">
			<div class="select_condition_row" name="form1" >
				  数据类型:
				<select style="width:110px;" id="select_con">
					<option value="1000" οnclick="selectBusinessHall()" >营业厅</option>
					<option value="1002" οnclick="selectVillageMessage()">4G参数</option>
					<option value="1003" οnclick="selectBasestationInforplan()">基站信息规划</option>
					<option value="1001" οnclick="showMr()">MR数据配置</option>
				</select>
				<span id="datePage" style="right:10px;position:absolute;"></span>
			</div>
			<div class="select_condition_row select_button" id="exim">
				<span><a οnclick="improtExample()">模板上传</a></span>
				<span><a οnclick="DownloadExample()">模板下载</a></span>
				<span><a οnclick="imports()">导入</a></span>
			</div>
			<input type="file" id="file" name=""   οnchange="fileChange(this)" style="FILTER: alpha(opacity=0); moz-opacity: 0; opacity: 0;" />
			<input type="file" id="uploadifys" name="myfiles"  multiple="multiple" οnchange="fileChanges(this)" style="FILTER: alpha(opacity=0); moz-opacity: 0; opacity: 0;" />
		</div>

js代码如下:
/**
 * 模板上传
 */
function improtExample(){
	var ie = !-[1,];   
	if(ie){  
		$("#uploadifys").trigger('click').trigger('change');  
	}else{  
		$("#uploadifys").trigger('click');  
	}  
}

/**
 * 模板上传
 * @param even
 */
function fileChanges(even){
	 var ss = document.getElementById("uploadifys").files;//js中取到其中对象
//	 var fileName=$("#uploadify")[0].files[0].name;
	if((ss.length)!=0){
		$.messager.confirm('提示','确定您要导入配置?',function(r){
			if (r){
				myMask.show();
			//	$('#uploadify').attr("name",$('#uploadify').val());
				$.ajaxFileUpload({
					url: path+'/SystemSiteController/importTemplateData.do',
					secureuri: false,//异步
					fileElementId: 'uploadifys',//上传控件ID
					dataType: 'text',//返回的数据信息格式
					success: function(data){
						myMask.hide();
						if(data == "<pre>true</pre>"){
							$.messager.alert('提示',"上传模板成功");
						}
					}
				})
			}
		});
	}else{
		$.messager.alert('提示',"请先选择文件!!");
	}
}
controller代码如下:

/**
	 * 模板数据上传
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping("importTemplateData")
	public void importTemplateData(HttpServletRequest request, HttpServletResponse response, @RequestParam MultipartFile[] myfiles) throws IOException {
		logger.info("**********into method importData*************");
		boolean isTrue = false;
		// 设置上下文
	//	MultipartFile myfile = myfiles[1];
	//	System.out.println("name="+myfile.getName()+",size="+ myfile.getSize()+ ",OriginalFilename="+ myfile.getOriginalFilename() );
		InputStream is = null;
		FileOutputStream output = null;
			for(int i=0;i<myfiles.length;i++){
				MultipartFile myfile = myfiles[i];
				String myfileName = myfile.getOriginalFilename();
				try {
					is = myfile.getInputStream();//MultipartFile转成输入流FileOutputStream
					 String path = (request.getSession().getServletContext().getRealPath("")).replace("\\", "/") +"systemPage/";
					 String name = myfile.getOriginalFilename();
					 System.out.println("******"+path+"********");
	                 File file = new File(path, name); 
	                 System.out.println(path);
	                 if (!file.exists()) {  
	                     file.createNewFile();  
	                 }  
					output = new FileOutputStream(file);
		            byte[] b = new byte[1024];
		            while (is.read(b) != -1) {
		                output.write(b);
		                b = new byte[1024];
		            }
				} catch (IOException e) {
					response.getWriter().print(isTrue);
				}
			}
		 try {
			isTrue = true;
			response.getWriter().print(isTrue);
			output.close();
			is.close();
		 } catch (IOException e1) {
			e1.printStackTrace();
		 }
	}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值