Java TagSupport实现Web权限验证标签
来源:互联网 发布:双拼域名.com 编辑:程序博客网 时间:2024/06/10 12:28
权限控制:
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;
}
}
0 0
- Java TagSupport实现Web权限验证标签
- Java TagSupport实现Web权限验证标签
- Java TagSupport实现Web非权限验证标签
- Java TagSupport实现Web非权限验证标签
- Java TagSupport实现Web分页标签
- Java TagSupport实现Web页面执行时间标签
- TagSupport 自定义权限标签
- 借助TagSupport 实现自定义标签
- 借助TagSupport 实现自定义标签
- 借助TagSupport 实现自定义标签
- 借助TagSupport 实现自定义标签
- Java web实现登录验证和过滤器权限设置
- 利用TagSupport创建自定义标签实现网页左侧菜单
- 自定义标签(TagSupport)!!!
- 自定义标签(TagSupport )
- TagSupport标签的应用
- jsp自定义标签 TagSupport
- 使用TagSupport自定义标签
- Android软键盘在清单文件中所有属性解释大全
- 遮罩层 CCClippingNode Stencil buffer is not enabled (ios/android)
- box2d 碰撞监听
- MAVEN常用命令
- C++处理URL的方法,项目有用到,过程记录如下
- Java TagSupport实现Web权限验证标签
- 接口能实例化
- [转]签了工作之后才发现,自己太草率了!(很长很真实!但会对你有所帮助的!)
- JAVA 参数传递
- 九度OJ 1526 朋友圈
- 作业2
- Web_CSS_通过不断设置广告位置来实现广告停留视野效果;
- Linux常用命令大全
- gdb调试技术