隨筆 - 11  文章 - 11  trackbacks - 0

          留言簿(2)

          隨筆分類(13)

          隨筆檔案(11)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          在Struts1.1-1.2中如果不想沒有登錄的用戶訪問一些action,可以擴展RequestProcessor,并重載processProprocess方法,在其中進行驗證

          public class CustomRequestProcessor
                  extends RequestProcessor {
              protected boolean processPreprocess (
                      HttpServletRequest request,
                      HttpServletResponse response) {
                  HttpSession session = request.getSession(false);
                  //If user is trying to access login page
                  // then don't check
                  if( request.getServletPath().equals("/loginInput.do")
                      || request.getServletPath().equals("/login.do") )
                      return true;
                  //Check if userName attribute is there is session.
                  //If so, it means user has allready logged in
                  if( session != null &&
                  session.getAttribute("userName") != null)
                      return true;
                  else{
                      try{
                          //If no redirect user to login Page
                          request.getRequestDispatcher 
                              ("/Login.jsp").forward(request,response);
                      }catch(Exception ex){
                      }
                  }
                  return false;
              }
          }
          

          相應的,在struts-config.xml中加入controller元素

          <controller>
           <set-property  property="processorClass"
           value="com.sample.util.CustomRequestProcessor"/>
          </controller>
          

          但剛才看到在Struts1.3中,已經不再使用RequestProcessor,而是用ComposableRequestProcessor 來實現自定義的request響應。






          posted on 2007-04-09 18:52 hijeff 閱讀(446) 評論(0)  編輯  收藏 所屬分類: Struts

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


          網站導航:
           
          主站蜘蛛池模板: 秦皇岛市| 堆龙德庆县| 临武县| 聂荣县| 恩平市| 武汉市| 旬阳县| 霍山县| 赤壁市| 太原市| 扎兰屯市| 西平县| 邻水| 瑞丽市| 尼勒克县| 杭州市| 武夷山市| 金乡县| 常德市| 巨野县| 德庆县| 永丰县| 红桥区| 和静县| 永川市| 龙岩市| 临夏县| 通江县| 忻州市| 江津市| 武清区| 荆州市| 吉木乃县| 梁山县| 平安县| 抚松县| 通许县| 青神县| 封开县| 息烽县| 凤冈县|