自定义标签权限控制

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!-- 导入自定义标签 -->
<%@taglib uri="http://com.bide.jstl.web.util/role" prefix="role"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
<style type="text/css" >
.style1
{
	color:#a67090;
	font-family:10px;
	font-weight:bold;
}
</style>
  </head>
  
  <body>
  <SPAN  class="style1"><role:role roleName="num1">测试1</role:role></SPAN> <br>
  
  <SPAN class="style1"><role:role roleName="num2">测试2</role:role></SPAN> <br>
  
  <SPAN class="style1"><role:role roleName="num3">测试3</role:role></SPAN> <br>
  
  <SPAN class="style1"><role:role roleName="num4">测试4</role:role></SPAN> <br>
  </body>
</html>
action中代码:
 
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.bide.jstl.web.action;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bide.jstl.model.prisist.entity.Login;
import com.bide.jstl.model.services.CheckLogin;
import com.bide.jstl.util.AllGetDispatcher;
import com.bide.jstl.web.form.UserloginForm;

public class UserloginAction extends Action implements AllGetDispatcher{
	
	
	private CheckLogin checkLogin;
	
	public CheckLogin getCheckLogin() {
		return checkLogin;
	}

	public void setCheckLogin(CheckLogin checkLogin) {
		this.checkLogin = checkLogin;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		UserloginForm userloginForm = (UserloginForm) form;
		//Action只做业务控制,不实现业务逻辑
		Login login =new Login();
		login.setName(userloginForm.getStrName());
		login.setPassword(userloginForm.getStrPwd());
		HttpSession session=request.getSession();
		Set setRole=checkLogin.CheckUserlogin(login);
		if(null!=setRole)
		{
			//存放至作用域,然后跳转,再标签处理类里面做判断
			session.setAttribute("setRole", setRole);
			return mapping.findForward(SUCCESS);
		}
		else
			return mapping.findForward(ERROR);
		// TODO Auto-generated method stub
		
	}
}
自定义标签类:
package com.bide.jstl.util;
import java.util.Set;

import javax.servlet.jsp.tagext.BodyTagSupport;


public class TagClass extends BodyTagSupport{
	//封装属性
	private String roleName;
	
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	
	
	//自定义标签处理类继承至BodyTagSupport并重写doStrartTag或者doEndTag方法,该方法返回的是一个整形数值.
	public int doStartTag()
	{
		Set setRole=(Set) pageContext.getSession().getAttribute("setRole");
		if(null!=setRole&&setRole.contains(roleName))
		{
			return EVAL_BODY_INCLUDE;
		}
		return this.SKIP_BODY;
		
	}
}

  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值