zoukankan      html  css  js  c++  java
  • XML预览

    功能:  实现模板文件的预览

     模板实体类中有一个content字段,它的值是xml形式的,就是要预览它的内容; 

    实现思路:  在java后台中将这个xml内容以xml文件的形式保存到服务器上,然后将路径返回到前台,前台使用window.open()的方式访问这个文件,这个文件就会在浏览器中打开,浏览器打开xml文件就是一种预览的方式.

        /**
         * 预览模板-并生成模板文件
         * 
         * @param parameter
         * @return
         * @throws IOException 
         */
        @SuppressWarnings("deprecation")
        public Object getFileContent4XML(Map<String, DataSet> dataSetMap,Object parameter){
            
            Map<String, Object> outParameters= new HashMap<String,Object>();
            outParameters.put("suc", "true");
            try {
                DataSet dataSet=dataSetMap.get("datasetTemplate");
                // 这里只会有一条数据
                if(dataSet.getRecords()!=null && dataSet.getRecords().size()==1){
    // 拿到对象,它里面有content字段 MantisTemplate templete
    =(MantisTemplate)(dataSet.getRecords().iterator().next()); // request对象 HttpServletRequest request=((HttpDoradoContext) DoradoContext.getContext()).getRequest() ; String path=request.getRealPath("tmp/"); // templete对象的xml内容包含一些特殊的字符无法解析,需要作转义 ,按照目前的内容,只能对& 作转义 String temp=templete.getTemplateContent(); temp=temp.replaceAll("&", "&amp;"); //生成文件并将xml内容写入文件 File file =new File(path+File.separatorChar+templete.getName()+".xml"); OutputStream out= new FileOutputStream(file); out.write(temp.getBytes()); out.flush(); out.close();
    // 返回xml路径 retPath=http://localhost:8080/receipt
    String retPath
    =request.getRequestURL().toString(); retPath=retPath.replaceFirst(request.getServletPath().toString(), ""); outParameters.put("retPath",retPath); outParameters.put("retFile","/tmp/"+templete.getName()+".xml" ); }else{ outParameters.put("suc", "false"); } } catch (Exception e) { outParameters.put("suc", "false"); logger.error(e, "【异常】 [模板文件导入失败!] " + " 异常信息:" + e.getMessage()); } return outParameters; }

     前台的处理

                var suc = command.outParameters().getValue("suc");
                        if(suc == 'false'){
                            alert("预览模板失败!");
                            return false;
                        }else{
                            var  retPath= command.outParameters().getValue("retPath");
                            var  retFile= command.outParameters().getValue("retFile");
                            // 在当前页面中打开时使用 location.href=retPath+encodeURIComponent(retFile);
                       // 在新的窗口中打开时使用 open()方法
                            open(retPath+encodeURIComponent(retFile),'_blank','top=210,left=220,height=455,width=1120,directories=no,titlebar=no,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no');
                        }

    JavaScript打开新窗口的更多详细的说明,请访问:

    http://www.cnblogs.com/yangw/p/4752473.html

    ----------- 赠人玫瑰,手有余香     如果本文对您有所帮助,动动手指扫一扫哟   么么哒 -----------


    未经作者 https://www.cnblogs.com/xin1006/ 梦相随1006 同意,不得擅自转载本文,否则后果自负
  • 相关阅读:
    第十章 CALL和RET指令
    第九章 转移指令的原理
    第八章 数据处理的两个基本问题
    实验九 根据材料编程
    第七章 更灵活的定位内存地址的方法
    第六章 包含多个段的程序
    实验五 编写、调试具有多个段的程序
    实验四 [bx]和loop的使用
    第五章 【BX】和loop指令
    第四章 第一个程序
  • 原文地址:https://www.cnblogs.com/xin1006/p/4752787.html
Copyright © 2011-2022 走看看