加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

模仿ajax利用rest导出文件

发布时间:2020-12-16 01:51:33 所属栏目:百科 来源:网络整理
导读:var form=$("form");//定义一个form表单form.attr("style","display:none");form.attr("target","");form.attr("method","get");form.attr("action",serverUrl);var input1=$("input");input1.attr("type","hidden");input1.attr("name","dicGuid");input1.a
var form=$("<form>");//定义一个form表单
	form.attr("style","display:none");
	form.attr("target","");
	form.attr("method","get");
	form.attr("action",serverUrl);
	var input1=$("<input>");
	input1.attr("type","hidden");
	input1.attr("name","dicGuid");
	input1.attr("value",dictionaryGuid);
	$("body").append(form);//将表单放置在web中
	form.append(input1);

	form.submit();//表单提交 

public Representation get() throws ResourceException {
		Form form = getRequest().getResourceRef().getQueryAsForm() ;    //获取查询参数  
		String dicGuid = form.getFirstValue(PARAM_DICTIONARY_DICTIONARYID).trim();
		DictionaryBean dicBean;
		try {
			dicBean = ChapterUtil.getDictionary(dicGuid);
		} catch (FileException e) {
			throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,"获取词典库失败");
		}
		String name = dicBean.getName();
		String content = listToStr(dicBean.getContent());
		
		final byte[] bpmnBytes;
		try {
			bpmnBytes = content.getBytes("UTF-8");
			Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT);
		    disposition.setFilename(new String(name.getBytes("utf-8"),"ISO_8859_1") + ".txt");
			OutputRepresentation output = new OutputRepresentation(MediaType.APPLICATION_OCTET_STREAM) {
	             
				public void write(OutputStream os)
	                     throws IOException
	             {
	                 os.write(bpmnBytes);
	                 os.flush();
	             }
	         };
	         output.setDisposition(disposition);
	         return output;
		} catch (UnsupportedEncodingException e) {
			throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,"获取词典库失败");
		}
	}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读