<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 14, comments - 22, trackbacks - 0, articles - 4
      BlogJava :: 首頁 ::  :: 聯系 :: 聚合  :: 管理

    如果用戶直接輸入了地址,不也可以直接訪問嗎?理論上是,我們可以加入session進行跟蹤,以杜絕此類型事件發生,我們是不是要把每次對session的判斷依次拷到每個頁里呢,之后下次需要驗證的SESSION換了,我們再換?太浪費了,我的做法是做了一個自定義標簽,來解決這個問題。

    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.tagext.TagSupport;

    public class CheckTag extends TagSupport
    {
    ??? private static final long serialVersionUID = 879137944441282895L;
    ??? private String check = "";//用來驗證的變量
    ??? private String url = "index.jsp";//出現錯誤要去的頁面
    ??? private String msg = "";//錯誤的提示
    ??? private String scope = "";//要嚴整變量的范圍
    ??? private String to = "go";
    //如果驗證失敗,是將頁面后退,還是定位到哪里?

    ??? public String getTo()
    ??? {
    ??????? return to;
    ??? }

    ??? public void setTo( String to )
    ??? {
    ??????? this.to = to;
    ??? }

    ??? public String getMsg()
    ??? {
    ??????? return msg;
    ??? }

    ??? public void setMsg( String msg )
    ??? {
    ??????? this.msg = msg;
    ??? }

    ??? public String getScope()
    ??? {
    ??????? return scope;
    ??? }

    ??? public void setScope( String scope )
    ??? {
    ??????? this.scope = scope;
    ??? }

    ??? public String getCheck()
    ??? {
    ??????? return check;
    ??? }

    ??? public void setCheck( String check )
    ??? {
    ??????? this.check = check;
    ??? }

    ??? public String getUrl()
    ??? {
    ??????? return url;
    ??? }

    ??? public void setUrl( String url )
    ??? {
    ??????? this.url = url;
    ??? }

    ??? public int doStsrtTag() throws JspException
    ??? {
    ??????? return SKIP_BODY;
    ??? }

    ??? public int doEndTag() throws JspException
    ??? {
    ??????? boolean valid = false;//先設為不可用
    ??????? if ( scope.equalsIgnoreCase( "request" ) )//如果要檢查request范圍
    ??????? {
    ??????????? valid = CheckUtil.checkRequestAttribute( pageContext.getRequest(),
    ??????????????????? check );
    ??????? }
    ??????? else if ( scope.equalsIgnoreCase( "session" ) )
    ??????? {
    ??????????? valid = CheckUtil.checkSession( pageContext.getSession(), check );
    ??????? }
    ??????? else if ( scope.equalsIgnoreCase( "parameter" ) )
    ??????? {
    ??????????? valid = CheckUtil.checkParameter( pageContext.getRequest(), check );
    ??????? }
    ??????? else if ( scope.equalsIgnoreCase( "application" ) )
    ??????? {
    ??????????? valid = CheckUtil.checkApp( pageContext.getServletContext(), check );
    ??????? }
    ??????? if ( valid ) return EVAL_PAGE;//如果可用就繼續執行此頁的其余部分
    ??????? else
    ??????? {//否則,哈哈
    ??????????? try
    ??????????? {
    ??????????????? if ( to.equalsIgnoreCase( "go" ) ) //現在失敗了,就看怎么回到你該到的地方
    ??????????????????? HtmlUtil.callParentGo(
    ??????????????????????? pageContext.getOut(), msg, url );//將瀏覽器定位到URL?
    ??????????????? else
    ??????????????????? HtmlUtil.callBack( pageContext.getOut(), msg );//后退一下頁面來阻止
    ??????????????? return SKIP_PAGE;//跳過頁面的其余部分,不執行
    ??????????? }
    ??????????? catch ( Exception e )
    ??????????? {
    ??????????????? throw new JspException( e.toString() );
    ??????????? }
    ??????? }
    ??? }

    ??? public void release()
    ??? {
    ??????? super.release();
    ??????? check = "";
    ??????? url = "";
    ??????? msg = "";
    ??????? scope = "";
    ??? }
    }


    下面是用到的htmlUtil部分:

    public static void callParentGo( Writer out, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? out.write( "<script language=\"javascript\">" );
    ??????? out.write( "alert(\"" + msg + "\");" );
    ??????? out.write( "parent.location.href=\"" + url + "\";" );
    ??????? out.write( "</script>" );
    ??? }
    public static void callBack( Writer out, String msg ) throws IOException
    ??? {
    ??????? out.write( "<script language=\"javascript\">" );
    ??????? out.write( "alert(\"" + msg + "\");" );
    ??????? out.write( "parent.history.back();" );
    ??????? out.write( "</script>" );
    ??? }


    寫個check.tld部署吧,

    <?xml version = "1.0"?>
    <taglib>
    ?<tlibversion>1.0</tlibversion>
    ?<jspversion>1.1</jspversion>
    ?<tag>
    ??<name>check</name>
    ??<tag-class>com.boya.subject.util.CheckTag</tag-class>
    ??<attribute>
    ???<name>check</name>
    ???<required>true</required>
    ??</attribute>
    ??<attribute>
    ???<name>url</name>
    ???<required>false</required>
    ??</attribute>
    ??<attribute>
    ???<name>msg</name>
    ???<required>true</required>
    ??</attribute>
    ??<attribute>
    ???<name>scope</name>
    ???<required>true</required>
    ??</attribute>
    ??<attribute>
    ???<name>to</name>
    ???<required>false</required>
    ??</attribute>
    ?</tag>
    </taglib>


    只要在每個頁面里寫下這個就可以判定用戶是否登陸了

    <%@ taglib prefix="boya" uri="/WEB-INF/check.tld" %>
    <boya:check check="admin" msg="管理員尚未登陸,請登陸!" scope ="session"/>

    如果沒有登陸那么,會自動提示到首頁登陸,不錯,很完美吧?

    當然不是,您可以提出您的見解。。。。


    評論

    # re: 體驗Struts(6)---阻止非法的登陸方式  回復  更多評論   

    2009-11-02 14:17 by dawnlch
    這樣是可以阻止用戶的登錄,但是不能阻止登錄的用戶通過輸入網址去操作他并沒有的權限啊!請問這要怎么解決啊

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    有事在這里給我留言噢!
    主站蜘蛛池模板: 日本中文字幕免费高清视频| 国产97视频人人做人人爱免费| 国产亚洲综合成人91精品| 最新亚洲人成无码网站| 午夜两性色视频免费网站| 亚洲色在线无码国产精品不卡| 一区二区无码免费视频网站| 亚洲国产成+人+综合| 成人午夜性A级毛片免费| 亚洲精品无码久久久久牙蜜区| 丰满人妻一区二区三区免费视频| 亚洲成人一区二区| 中国一级特黄的片子免费 | 免费一区二区视频| 亚洲黄色中文字幕| 黄色片在线免费观看 | 中文字幕在线日亚洲9| 国产精品酒店视频免费看| 黄色a三级免费看| 亚洲AV无码久久精品成人| 免费无遮挡无码永久视频| 亚洲videos| 久久成人无码国产免费播放| 久久久久亚洲AV无码专区体验 | 国产无遮挡吃胸膜奶免费看视频 | 免费中文字幕一级毛片| 成人无码视频97免费| 亚洲最大黄色网站| 日本一区免费电影| 十八禁视频在线观看免费无码无遮挡骂过 | 久久精品国产亚洲av麻豆图片| 成人毛片免费网站| av午夜福利一片免费看久久| 亚洲AV无码专区国产乱码4SE| 在线观看免费人成视频色9| 日韩精品免费一线在线观看 | 污视频网站在线免费看| 亚洲av无码不卡| 在线免费观看韩国a视频| 国产偷伦视频免费观看| 亚洲av午夜国产精品无码中文字|