隨筆 - 11  文章 - 11  trackbacks - 0

          留言簿(2)

          隨筆分類(13)

          隨筆檔案(11)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          在Struts1.1-1.2中如果不想沒有登錄的用戶訪問一些action,可以擴(kuò)展RequestProcessor,并重載processProprocess方法,在其中進(jìn)行驗(yà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 @ 2007-04-09 18:52 hijeff 閱讀(446) | 評(píng)論 (0)編輯 收藏
          主站蜘蛛池模板: 封丘县| 泸溪县| 丰原市| 二连浩特市| 潼南县| 阿瓦提县| 资兴市| 临沧市| 孟州市| 从化市| 祁东县| 盐源县| 邵阳县| 邹平县| 平顶山市| 龙泉市| 崇明县| 枣强县| 朔州市| 会宁县| 彭州市| 依兰县| 吴堡县| 含山县| 柏乡县| 留坝县| 鹤岗市| 甘德县| 潜山县| 泾阳县| 拜泉县| 淅川县| 久治县| 陈巴尔虎旗| 渝中区| 桃园市| 唐海县| 曲周县| 梅河口市| 青岛市| 丰县|