Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30468068
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: Java

2009-03-21 00:22:53

功能 :判断当前用户是否有权限访问当页面
????思路:读取当前用户的权限(在登陆验证是设置的)
???? ?? 和标签在jsp页面取到的值进行比较,不匹配时跳转到指定页面
????总结:标签类一般存放在web-inf/lib?
??? ? xxxx.tld 配置 标签类的参数定义和指定类名
???? ? web-inf.xml 指定xxxx.tld的位置和定义名字
???? ?
????错误总结:写标签类的时候get/set方法漏了 ,报错。
???? ? 写jsp页面时ctrl c ctrl v时 uri没改,页面不认。
????下步目标:标签类进行验证时能将验证错误信息写入session或者request
???? ? 然后能通过jsp页面读取到该错误信息
????
????
????===================CheckPower.class(标签类程序)==================================
????package com.mytld;
????
????import java.io.IOException;
????
????import javax.servlet.jsp.JspException;
????import javax.servlet.jsp.tagext.TagSupport;
????
????public class CheckPower extends TagSupport {
????
???? private String power;
????
???? private String gotoPage;
????
???? public int doEndTag() throws JspException {
???? String userPower = (String) pageContext.getSession().getAttribute(
???? "power");
???? try {
???? if (!power.equals(userPower)) {
???? pageContext.forward(gotoPage);
???? return super.EVAL_PAGE;
???? }
???? } catch (Exception e) {
???? e.printStackTrace();
???? }
????
???? return super.EVAL_PAGE;
???? // return super.SKIP_BODY ;
???? // return super.SKIP_PAGE;
???? }
????
???? public String getGotoPage() {
???? return gotoPage;
???? }
????
???? public void setGotoPage(String gotoPage) {
???? this.gotoPage = gotoPage;
???? }
????
???? public String getPower() {
???? return power;
???? }
????
???? public void setPower(String power) {
???? this.power = power;
???? }
????
????}
????================manager.jsp==================================
????<%@ page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
????<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
????<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
????<%@ taglib uri="mytag" prefix="mytag" %>
????
????
????
????manager
????
????
????
manager

????
????
????
????

????
????
????
????================mytag.tld===================
????
????
????1.2
????1.1
????mytag
????
????
????CheckPower
????com.mytld.CheckPower
????
????power
????true
????true
????

????
????
????gotoPage
????true
????true
????

????
????

????
????

????
????
????==================web.xml(片断)===========================
????
???? mytag
???? /WEB-INF/mytag.tld
????
阅读(2277) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-08-21 15:04:52

学习