Java TagSupport实现Web权限验证标签
2014-03-03 17:08
351 查看
权限控制:
jsp
<%@ taglib prefix="priveliege" uri="/WEB-INF/tlds/priveliege.tld" %>
<priveliege:priveliege funCode="switchSite">
<input type="button" value='<s:text name="msg.portalMS.iepg.site.change"/>' id="button" onclick="showPageTask2('<s:text name="msg.portalMS.iepg.site.change"/>','<%=request.getContextPath()%>/Site/queryValidateSites.action',652,466,'<%=request.getContextPath()%>/Site/queryIepg.action');"/>
</priveliege:priveliege>
create table T_SYS_RIGHT
(
right_id NUMBER(13) not null,
right_name VARCHAR2(100) not null,
right_url VARCHAR2(2000),
parent_right_id NUMBER(13),
right_level NUMBER(1),
status NUMBER(2) not null,
function_code VARCHAR2(50),
level_type VARCHAR2(2)
)
function_code = 'switchSite' 则有权限
priveliege.tld:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.1</jsp-version>
<short-name>priveliegeTag</short-name>
<uri>priveliegeTag</uri>
<tag>
<name>priveliege</name><!--另一个标签的别名-->
<tag-class>
com.xxx.sdp.rights.view.action.taglib.PrivilegeTag
</tag-class><!--标签类文件的物理地址-->
<body-content>Jsp</body-content><!--看看是不是具有标签体-->
<attribute><!--带参数的标签必须写-->
<name>funCode</name><!--属性名称-->
<required>false</required><!--当前的属性是否是必须的-->
<rtexprvalue>true</rtexprvalue><!-- 是否通过程序代码进行赋值-->
</attribute>
</tag>
</taglib>
package com.coship.dhm.portalMS.common.taglib;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import com.xxx.dhm.portalMS.common.Constants;
import com.xxx.sdp.rights.model.domain.Admin;
/**
*
* 权限标签类,通过引用此标签可以屏蔽不需要的功能. 1、在jsp页面中引入:<%@taglib uri="/WEB-INF/priveliege.tld"
* prefix="priveliege" %> 权限标签的TLD文件 2、在需要配制权限控制的地方加入:<priveliege:priveliege
* funCode="ModifyRegion">标签体</priveliege:priveliege>
* 3、funCode的值需与数据库权限表的function_code字段值一致,才能显示标签体,否屏蔽标签体
*
*/
public class PrivilegeTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Privilege> privilegeList = new ArrayList<Privilege>();
private String funCode;
private Privilege privielege;
public int doStartTag() throws JspException {
// 从容器内存中读取用户的功能列表
Admin loginUser = (Admin) this.pageContext.getSession().getAttribute(
Constants.LOGIN_USER.getStringValue());
/*
* 不再使用session "assignedPrivileges"了 modify by
* privilegeList = (List) this.pageContext.getSession().getAttribute(
* "assignedPrivileges");
*/
// 若session失效,则屏蔽功能
if (null == privilegeList) {
return TagSupport.SKIP_BODY;
}
privilegeList = PrivilegeURLCache.getPrivilegeList(loginUser
.getLoginName());
Iterator<Privilege> it = privilegeList.iterator();
funCode = funCode.trim();
if (null != funCode) {
while (it.hasNext()) {
privielege = it.next();
// 若此用户存此功能code,界面显示操作按钮
if ((privielege.getFunCode().equals(funCode))) {
return TagSupport.EVAL_PAGE;
}
}
}
return TagSupport.SKIP_BODY;
}
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
return TagSupport.EVAL_PAGE;
}
public List<Privilege> getPrivilegeList() {
return privilegeList;
}
public void setPrivilegeList(List<Privilege> privilegeList) {
this.privilegeList = privilegeList;
}
public String getFunCode() {
return funCode;
}
public void setFunCode(String funCode) {
this.funCode = funCode;
}
public Privilege getPrivielege() {
return privielege;
}
public void setPrivielege(Privilege privielege) {
this.privielege = privielege;
}
}
jsp
<%@ taglib prefix="priveliege" uri="/WEB-INF/tlds/priveliege.tld" %>
<priveliege:priveliege funCode="switchSite">
<input type="button" value='<s:text name="msg.portalMS.iepg.site.change"/>' id="button" onclick="showPageTask2('<s:text name="msg.portalMS.iepg.site.change"/>','<%=request.getContextPath()%>/Site/queryValidateSites.action',652,466,'<%=request.getContextPath()%>/Site/queryIepg.action');"/>
</priveliege:priveliege>
create table T_SYS_RIGHT
(
right_id NUMBER(13) not null,
right_name VARCHAR2(100) not null,
right_url VARCHAR2(2000),
parent_right_id NUMBER(13),
right_level NUMBER(1),
status NUMBER(2) not null,
function_code VARCHAR2(50),
level_type VARCHAR2(2)
)
function_code = 'switchSite' 则有权限
priveliege.tld:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.1</jsp-version>
<short-name>priveliegeTag</short-name>
<uri>priveliegeTag</uri>
<tag>
<name>priveliege</name><!--另一个标签的别名-->
<tag-class>
com.xxx.sdp.rights.view.action.taglib.PrivilegeTag
</tag-class><!--标签类文件的物理地址-->
<body-content>Jsp</body-content><!--看看是不是具有标签体-->
<attribute><!--带参数的标签必须写-->
<name>funCode</name><!--属性名称-->
<required>false</required><!--当前的属性是否是必须的-->
<rtexprvalue>true</rtexprvalue><!-- 是否通过程序代码进行赋值-->
</attribute>
</tag>
</taglib>
package com.coship.dhm.portalMS.common.taglib;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import com.xxx.dhm.portalMS.common.Constants;
import com.xxx.sdp.rights.model.domain.Admin;
/**
*
* 权限标签类,通过引用此标签可以屏蔽不需要的功能. 1、在jsp页面中引入:<%@taglib uri="/WEB-INF/priveliege.tld"
* prefix="priveliege" %> 权限标签的TLD文件 2、在需要配制权限控制的地方加入:<priveliege:priveliege
* funCode="ModifyRegion">标签体</priveliege:priveliege>
* 3、funCode的值需与数据库权限表的function_code字段值一致,才能显示标签体,否屏蔽标签体
*
*/
public class PrivilegeTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Privilege> privilegeList = new ArrayList<Privilege>();
private String funCode;
private Privilege privielege;
public int doStartTag() throws JspException {
// 从容器内存中读取用户的功能列表
Admin loginUser = (Admin) this.pageContext.getSession().getAttribute(
Constants.LOGIN_USER.getStringValue());
/*
* 不再使用session "assignedPrivileges"了 modify by
* privilegeList = (List) this.pageContext.getSession().getAttribute(
* "assignedPrivileges");
*/
// 若session失效,则屏蔽功能
if (null == privilegeList) {
return TagSupport.SKIP_BODY;
}
privilegeList = PrivilegeURLCache.getPrivilegeList(loginUser
.getLoginName());
Iterator<Privilege> it = privilegeList.iterator();
funCode = funCode.trim();
if (null != funCode) {
while (it.hasNext()) {
privielege = it.next();
// 若此用户存此功能code,界面显示操作按钮
if ((privielege.getFunCode().equals(funCode))) {
return TagSupport.EVAL_PAGE;
}
}
}
return TagSupport.SKIP_BODY;
}
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
return TagSupport.EVAL_PAGE;
}
public List<Privilege> getPrivilegeList() {
return privilegeList;
}
public void setPrivilegeList(List<Privilege> privilegeList) {
this.privilegeList = privilegeList;
}
public String getFunCode() {
return funCode;
}
public void setFunCode(String funCode) {
this.funCode = funCode;
}
public Privilege getPrivielege() {
return privielege;
}
public void setPrivielege(Privilege privielege) {
this.privielege = privielege;
}
}
相关文章推荐
- Java TagSupport实现Web权限验证标签
- Java TagSupport实现Web非权限验证标签
- Java TagSupport实现Web非权限验证标签
- Java TagSupport实现Web页面执行时间标签
- Java TagSupport实现Web分页标签
- 通过servlet.jsp.tagext.TagSupport的自定义标签实现按钮权限控制
- WEB.CONFIG 实现 不同文件夹下 FORM验证的访问权限
- 利用TagSupport创建自定义标签实现网页左侧菜单
- Java web图片验证功能实现二
- Java web自定义标签按钮级别权限控制完美诠释(jplogic 快速开发平台)
- Web用户的身份验证及WebApi权限验证流程的设计和实现
- 实现一个可配置的java web 参数验证器
- 借助TagSupport 实现自定义标签
- Web用户的身份验证及WebApi权限验证流程的设计和实现
- java web中图片验证码功能的简单实现方法
- java web从零单排第七期《struts2》用ActionSupport类验证提交表单
- JAVAWEB开发之Servlet3.0新特性的使用以及注解的详细使用和自定义注解的方法、动态代理的使用、利用动态代理实现细粒度的权限控制以及类加载和泛型反射
- Java正则表达式实现web端输入验证
- 权限管理(java+struts2(自定义标签)实现)--------->全代码演示
- Web用户的身份验证及WebApi权限验证流程的设计和实现(续)