隨筆 - 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 來實(shí)現(xiàn)自定義的request響應(yīng)。






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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 丰宁| 菏泽市| 左贡县| 辉县市| 历史| 博野县| 孝昌县| 连城县| 灌云县| 天长市| 邢台市| 若羌县| 湘潭市| 体育| 类乌齐县| 全南县| 东光县| 龙泉市| 巫溪县| 克拉玛依市| 柳林县| 安溪县| 达孜县| 介休市| 营口市| 北宁市| 建瓯市| 宁化县| 华宁县| 德保县| 大方县| 昭觉县| 合作市| 武清区| 辉南县| 吉木萨尔县| 海原县| 荔浦县| 喀喇沁旗| 方山县| 酒泉市|