隨筆 - 11  文章 - 11  trackbacks - 0

          留言簿(2)

          隨筆分類(13)

          隨筆檔案(11)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

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

          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;
              }
          }
          

          相應(yīng)的,在struts-config.xml中加入controller元素

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

          但剛才看到在Struts1.3中,已經(jīng)不再使用RequestProcessor,而是用ComposableRequestProcessor 來實現(xiàn)自定義的request響應(yīng)。






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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 泰来县| 公安县| 冀州市| 红安县| 南安市| 镇宁| 佳木斯市| 华阴市| 乌恰县| 龙岩市| 缙云县| 昌乐县| 龙川县| 重庆市| 福泉市| 南充市| 麻城市| 潜山县| 敦化市| 嘉义县| 临泽县| 望城县| 潞城市| 三穗县| 滨海县| 曲松县| 台江县| 如东县| 盈江县| 普兰店市| 安龙县| 鄂托克前旗| 砀山县| 平乐县| 安多县| 万全县| 黑河市| 福建省| 嘉祥县| 抚州市| 泗阳县|