部分页面:
<table width="100%" border="0" align="center" cellspacing="3" bgcolor="#FFFFFF"> <tr class="text5"> <td align="center"> <input type="hidden" name="selectNodeId" id="selectNodeId" value="" /> #btnOperate("/pas/business/chenYearAction!insert.do") <input type="button" class="input1" name="insertBtn" value=" 新增 " id="insertBtn"/> #end #if ($chenYears.size() > 0) #btnOperate("/pas/business/chenYearAction!update.do") <input type="button" class="input1" name="updateBtn" value=" 修改 " id="updateBtn"/> #end #btnOperate("/pas/business/chenYearAction!delete.do") <input type="button" class="input1" name="deleteBtn" value=" 删除 " id="deleteBtn"/> #end #end </td> </tr> </table>
配置:
在/WEB-INF/velocity.properties(没有就创建一个)中添加:
userdirective=com.shop.pas.system.util.VelocityTagDirective
处理JAVA类:VelocityTagDirective.java
package com.shop.pas.system.util; import java.io.IOException; import java.io.Writer; import org.apache.velocity.context.InternalContextAdapter; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.directive.Directive; import org.apache.velocity.runtime.parser.node.Node; import org.apache.velocity.runtime.parser.node.SimpleNode; /** * velocity 控制页面展示问题 #btnOperate("权限连接") 被控制部分 #end * * @author chenweixian * */ public class VelocityTagDirective extends Directive { // 指定指令的名称 @Override public String getName() { return "btnOperate"; } // 指定指令类型为块指令 @Override public int getType() { return BLOCK; } // 指令内容操作 @Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { // 获得缓存信息 SimpleNode sn_region = (SimpleNode) node.jjtGetChild(0); // 获得请求连接 String requestUrl = (String) sn_region.value(context); // 判断当前用户是否有此连接权限 try { if (UserAccessFlag.flagIsAllowAccess(requestUrl)) { // 显示被自定义标签内的内容 SimpleNode sn_key = (SimpleNode) node.jjtGetChild(1); sn_key.render(context, writer); } } catch (Exception e) { } return true; } }