- 爱易网页
-
JavaSript
- 自定义jsp标签治理按钮权限
日期:2014-05-16 浏览次数:20447 次
自定义jsp标签管理按钮权限
1:自定入jsp标签,放入WEB-INF下,标签名为:buttonPower.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>buttonPower core library</description>
<display-name>buttonPower core</display-name>
<tlib-version>1.1</tlib-version>
<short-name>centfor</short-name>
<uri>http://www.asia-home.com.cn/buttonPower</uri>
<tag>
<description>按钮参数</description>
<name>buttonList</name>
<tag-class>com.asia.home.cn.web.tag.power.ButtonTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>bindPowerName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
2:ButtonTag 标签类
package com.asia.home.cn.web.tag.power;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import com.asia.home.cn.base.BaseEnvironment;
import com.asia.home.cn.buttonManage.ButtonManage;
import com.asia.home.cn.services.buttonManage.IButtonManageService;
public class ButtonTag extends TagSupport {
private static final long serialVersionUID = 1L;
private IButtonManageService buttonService;
Logger InfoLogger = Logger.getLogger("loginfo");
private String bindPowerName;
protected void init() {
if(buttonService == null){
ApplicationContext applicationContext = BaseEnvironment.getApplicationContext();
buttonService = (IButtonManageService) applicationContext.getBean("buttonService");
}
}
@Override
public int doStartTag() throws JspException {
init();
try {
String fsRightId = queryUserButtonPower(bindPowerName);
ButtonManage buttonParam = null;
if(fsRightId!=null){
buttonParam = buttonService.queryButtonByPowerId(fsRightId);
}
if (buttonParam==null) {
pageContext.getRequest().setAttribute("flag", 0);
return EVAL_BODY_INCLUDE;
}
pageContext.getRequest().setAttribute("buttonParam", buttonParam);
} catch (Exception e) {