軟件藝術(shù)思考者  
          混沌,彷徨,立志,蓄勢...
          公告
          日歷
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          隨筆分類(86)

          隨筆檔案(85)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           
          在平時的項(xiàng)目中經(jīng)常的用到請求分發(fā),每次都要重復(fù)的寫如下代碼: RequestDispatcher dispatcher = getServletContext() .getRequestDispatcher("/public/errmsg.jsp"); dispatcher.forward(request, response); 我們可以一個 public abstract class ServletMNG extends HttpServlet類,其中封裝此方法: /** * 請求重定向到指定的url。每個Servlet的方法都會用到 * @param request * @param response * @param url 重定向的url,可以代參數(shù) * @author aimonica */ public void forward(HttpServletRequest request, HttpServletResponse response, String url) { try { RequestDispatcher dispatcher = getServletContext() .getRequestDispatcher(url); dispatcher.forward(request, response); } catch (Exception ex) { ex.printStackTrace(System.out); handleException(response, ex); } } 其他的servlet都繼承此類。便可以在子類中通過以下方式輕松調(diào)用:forward(request,response,url). 項(xiàng)目有好多的地方,都可以用類似的封裝
          posted on 2006-07-05 17:23 智者無疆 閱讀(97) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
           
          Copyright © 智者無疆 Powered by: 博客園 模板提供:滬江博客


             觀音菩薩贊

          主站蜘蛛池模板: 莱芜市| 温泉县| 鱼台县| 丹东市| 中西区| 筠连县| 且末县| 尤溪县| 浠水县| 宁国市| 湘阴县| 雷州市| 江陵县| 邵阳县| 崇州市| 确山县| 益阳市| 瓦房店市| 鄂托克前旗| 公安县| 平顺县| 湾仔区| 巴东县| 额尔古纳市| 敦化市| 灌南县| 曲周县| 遵化市| 开封市| 开化县| 西林县| 崇文区| 信宜市| 繁峙县| 长岛县| 禹城市| 皋兰县| 托里县| 永和县| 河曲县| 大同县|