@Override public boolean render(InternalContextAdapter icad, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { Map params = getPareMap(icad, node); VelocityContext context = new VelocityContext(); context.put("imageDomain", imageDomain); context.put("cssDomain", cssDomain); context.put("jsDomain", jsDomain); context.put("sbglpath", sbglpath); context.put("strutsaction", strutsaction); context.put("webbaseurl", webbaseurl); System.out.println("ssssssssssssssssssss"); try { // 获取文件路径 FrontDirective frontdirective = (FrontDirective) Class.forName("com.sbgl.actions" + params.get("moduleName") + "Action").newInstance(); // 处理参数 Object isPas = params.get("parameters"); if (isPas != null) { setParem(params); } String tag = params.get("tag").toString(); if ("HEAD".equals(tag)) { frontdirective.head(icad, params, context); } else if ("FOOT".equals(tag)) { frontdirective.foot(icad, params, context); } else if ("WINDOW".equals(tag)) { frontdirective.window(icad, params, context); } String vmpath = params.get("vmpath").toString(); icad.pushCurrentTemplateName(vmpath); Properties properties = new Properties(); String basePath = ServletActionContext.getServletContext().getRealPath("/"); properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, basePath); // 设置velocity的编码 properties.setProperty(Velocity.ENCODING_DEFAULT, "utf-8"); properties.setProperty(Velocity.INPUT_ENCODING, "utf-8"); properties.setProperty(Velocity.OUTPUT_ENCODING, "utf-8"); /* 首先创建一个模板引擎的实例,并予以初始化 */ VelocityEngine engine = new VelocityEngine(); engine.init(properties); /* 接着,获得一个模板 */ Template template = engine.getTemplate(icad.getCurrentTemplateName()); /* 现在,把模板和数据合并,输出到StringWriter */ StringWriter wri = new StringWriter(); template.merge(context, wri); /* 显示结果 */ writer.write(wri.toString()); } catch (Exception e) { e.printStackTrace(); } return true; }