a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > JSP > 正文

Struts1之url截取_動力節點Java學院整理

2024-09-05 00:23:22
字體:
來源:轉載
供稿:網友

Struts1之url截取

先我們來對ActionServlet深層次進行分析。我們用斷點的調試的方式來看底層源碼。因為這個實例是post方式提交,所以將斷點設置到doPost方法上。


 url截取,Struct

      我們debug運行程序,進入doPost里面的方法: 

url截取,Struct

        這個方法非常重要是ActionServlet運行的核心方法。

        我們進入這個方法:

    url截取,Struct

       再繼續進入:


url截取,Struct

      我們赫然發現了這樣一個方法就是processPath方法,這個方法就是截取字符串的方法。這個方法的源代碼如下:

/**   * <p>Identify and return the path component(from the request URI) that   * we will use to select an <code>ActionMapping</code> with which todispatch.   * If no such path can be identified,create an error response and return   * <code>null</code>.</p>   *   * @param request The servlet request weare processing   * @param response The servlet response weare creating   *   * @exception IOException if an input/outputerror occurs   */  protectedString processPath(HttpServletRequest request,         HttpServletResponse response)   throws IOException {    String path = null;    // For prefix matching, match on the path info (if any)   path = (String) request.getAttribute(INCLUDE_PATH_INFO);   if (path == null) {    path = request.getPathInfo();   }   if ((path != null) && (path.length() > 0)) {    return (path);   }    // For extension matching, strip the module prefix and extension   path = (String) request.getAttribute(INCLUDE_SERVLET_PATH);   if (path == null) {    path = request.getServletPath();   }   String prefix = moduleConfig.getPrefix();   if (!path.startsWith(prefix)) {    String msg =getInternal().getMessage("processPath");        log.error(msg + " " + request.getRequestURI());    response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);     return null;   }      path = path.substring(prefix.length());   int slash = path.lastIndexOf("/");   int period = path.lastIndexOf(".");   if ((period >= 0) && (period >slash)) {    path = path.substring(0, period);   }   return (path);  } 

分析一下這段代碼: 

path = (String)request.getAttribute(INCLUDE_PATH_INFO);   if (path == null) {    path = request.getPathInfo();   }   if ((path != null) && (path.length() > 0)) {    return (path);   } 

這段代碼首先判斷一下javax.servlet.include.path_info是否存在路徑信息,這里要知道當當一個頁面是以RequestDispatcher.include方式顯示的話,這個屬性值才存在。所以這里沒有值,就會進入path=request.getPathInfo()程序中,這里的getPathInfo獲取的值是相對servlet的路徑信息。

// For extension matching, stripthe module prefix and extension   path = (String) request.getAttribute(INCLUDE_SERVLET_PATH);   if (path == null) {    path = request.getServletPath();   }   String prefix = moduleConfig.getPrefix();   if (!path.startsWith(prefix)) {    String msg =getInternal().getMessage("processPath");        log.error(msg + " " + request.getRequestURI());    response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);     return null;   } 

        這一段代碼是判斷javax.servlet.include.servlet_path是否存在值,這個也是當一個頁面是以equestDispatcher.include方式顯示的話,這個屬性值才存在,所以這里的值沒有。之后進入path = request.getServletPath();這個方法是獲得返回請求URI上下文后的子串,所以這里的返回值就是“/”和訪問頁面名稱和后綴(這里和我的mvc實例截取的是不是一樣的道理)。隨后進入下面代碼:

path = path.substring(prefix.length());   intslash = path.lastIndexOf("/");   intperiod = path.lastIndexOf(".");   if((period >= 0) && (period > slash)) {    path = path.substring(0, period);   }   return (path); 

       這里的方法主要和我的上面的那里是一樣的,主要就是去掉后綴。


注:相關教程知識閱讀請移步到JSP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 一本色道久久综合狠狠躁篇的优点 | 天堂a| 国产综合久久久 | 久久午夜影视 | 91色视频在线观看 | 在线播放黄 | 黄色精品网站 | 日韩一区二区三区在线视频 | 精品国产乱码久久久久久闺蜜 | 中文字幕亚洲一区二区三区 | 毛片免费看| 亚洲欧美一区二区三区视频 | 久久在线视频 | 在线看免费黄色片 | 99精品久久久 | 日韩欧美在线中文字幕 | 欧美日韩成人在线视频 | 五月婷婷六月色 | 国产精品亚洲精品日韩已方 | 一级片视频免费 | 久久99精品视频 | 再深点灬舒服灬太大了添少妇视频 | 国产精品成人3p一区二区三区 | 国精日本亚洲欧州国产中文久久 | 精品久| 欧美日韩国产高清视频 | 国产网站在线播放 | 男人的天堂在线视频 | 一区免费 | www.色综合 | 国产电影一区二区 | 在线播放三级 | 四虎成人av | 国产精品久久久久久亚洲影视 | 免费大片在线观看网站 | 天天摸夜夜摸爽爽狠狠婷婷97 | 久久久精品999 | 欧美日韩精品 | 中文字幕亚洲精品 | 久久国产精品免费一区二区三区 | 国产一区二区在线看 |