老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

如何在Struts1中使用ActionMapping

這期內容當中小編將會給大家帶來有關如何在Struts1中使用ActionMapping,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創新互聯公司專注骨干網絡服務器租用10余年,服務更有保障!服務器租用,雅安移動機房 成都服務器租用,成都服務器托管,骨干網絡帶寬,享受低延遲,高速訪問。靈活、實現低成本的共享或公網數據中心高速帶寬的專屬高性能服務器。

首先斷點走出了processpath方法,

  如何在Struts1中使用ActionMapping

這個方法是用來截取字符串的,今天我們來看怎樣獲得ActionMapping的方法---processMapping。

在此之前簡單說一下ActionMapping,它的源代碼中可以看出,其中最重要的屬性和我們的mvc小實例中的ActionMapping類似,都是有path、type還有forwardMap,主要是對應的struts-config配置文件而來,這個就是保存這個配置文件的信息到內存中。

具體的mvc小實例的ActionMapping代碼如下:

package com.cjq.servlet; 
 
import java.util.Map; 
 
public class ActionMapping { 
 
  private String path; 
   
  private Object type; 
   
  private Map forwardMap; 
 
  public String getPath() { 
    return path; 
  } 
 
  public void setPath(String path) { 
    this.path = path; 
  } 
 
  public Object getType() { 
    return type; 
  } 
 
  public void setType(Object type) { 
    this.type = type; 
  } 
 
  public Map getForwardMap() { 
    return forwardMap; 
  } 
 
  public void setForwardMap(Map forwardMap) { 
    this.forwardMap = forwardMap; 
  } 
   
} 

而Struts中的Actionconfig(因為ActionMapping是繼承這個ActionConfig的,所以我們來看ActionConfig更加直接)的代碼如下:

如何在Struts1中使用ActionMapping

從這兩部分代碼來看,更加印證了我在開篇寫的mvc小實例是一個struts框架的雛形。

講完ActionMapping的一些內容后,相信對ActionMapping有所了解,那么系統是如何生成ActionMapping和如何找到ActionMapping的呢?這就是今天要說的整體:

我們看下web.xml中有一個2  配置信息,這個信息就是說明了但服務器已啟動就動態讀取struts-config配置文件把配置文件的信息put到ActionMapping中。所以當我們運行服務器的時候,我們在內存中已經存在對應struts-config配置文件信息對應的ActionMapping。今天就是要通過processMapping讀取這個ActionMapping類。

進入斷點調試,首先在processMapping方法上設置斷點。

如何在Struts1中使用ActionMapping    

進入源代碼中:

/** 
   * 

Select the mapping used to process theselection path for this request * If no mapping can be identified, createan error response and return * null.

* * @param request The servlet request weare processing * @param response The servlet response weare creating * @param path The portion of the requestURI for selecting a mapping * * @exception IOException if an input/outputerror occurs */ protectedActionMapping processMapping(HttpServletRequestrequest, HttpServletResponse response, String path) throws IOException { // Is there a mapping for this path? ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig(path); // If a mapping is found, put it in the request and return it if (mapping != null) { request.setAttribute(Globals.MAPPING_KEY, mapping); return (mapping); } // Locate the mapping for unknown paths (if any) ActionConfig configs[] = moduleConfig.findActionConfigs(); for (int i = 0; i < configs.length; i++) { if (configs[i].getUnknown()) { mapping = (ActionMapping)configs[i]; request.setAttribute(Globals.MAPPING_KEY, mapping); return (mapping); } } // No mapping can be found to process this request String msg = getInternal().getMessage("processInvalid"); log.error(msg + " " + path); response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); return null; }

首先我們傳入我們在上一步截取的路徑,通過moduleConfig的findAction方法來查找ActionConfig,并且返回ActionMapping。具體代碼是:

ActionMapping mapping =(ActionMapping) 
   moduleConfig.findActionConfig(path); 

如果找到,那么就講ActionMapping存放到request的context中。代碼:

if (mapping != null) { 
      request.setAttribute(Globals.MAPPING_KEY, mapping); 
      return (mapping); 
    } 

如果沒有通過path找到mapping,則在Actionconfig中遍歷為未知路徑尋找mapping,如果找到則存放到request中,如果沒有找到,則返回錯誤信息,具體代碼如下:

// Locate the mapping for unknownpaths (if any) 
    ActionConfig configs[] = moduleConfigfindActionConfigs(); 
    for (int i = 0; i < configslength; i++) { 
      if (configs[i].getUnknown()) { 
        mapping = (ActionMapping)configs[i]; 
        request.setAttribute(Globals.MAPPING_KEY, mapping); 
        return (mapping); 
      } 
    } 
  
    // No mapping can be found to process this request 
    String msg = getInternal().getMessage("processInvalid"); 
    log.error(msg + " " + path); 
    response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); 
     
    return null; 

來看下ActionServlet中的一個方法processActionForm,當我們在截取字符串,再根據字符串取得ActionMapping(這是前兩篇文章中介紹的)之后,我們就要用利用ActionMapping來創建ActionForm了,并且把ActionForm放到request或session中管理。

先來看具體struts中processActionForm方法的具體實現:

/** 
 
   * 

Retrieve and return the ActionForm associatedwith * this mapping, creating and retaining oneif necessary. If there is no * ActionForm associated with this mapping,return * null.

* * @param request The servlet request weare processing * @param response The servlet response weare creating * @param mapping The mapping we are using */ protectedActionForm processActionForm(HttpServletRequestrequest, HttpServletResponse response, ActionMapping mapping) { // Create (if necessary) a form bean to use ActionForm instance = RequestUtilscreateActionForm (request, mapping, moduleConfig, servlet); if (instance == null) { return (null); } // Store the new instance in the appropriate scope if (log.isDebugEnabled()) { log.debug(" Storing ActionForm bean instance in scope '" + mapping.getScope() + "' under attribute key '" + mapping.getAttribute() + "'"); } if ("request".equals(mapping.getScope())) { request.setAttribute(mapping.getAttribute(), instance); } else { HttpSession session =requestgetSession(); session.setAttribute(mapping.getAttribute(), instance); } return (instance); }

這個方法的大體流程是:根據ActionMapping中的name名稱查找ActionForm,如果配置了ActionForm,那么就到request或session中查找,如果在request或session中存在已經創建的ActionForm,那么將返回。如果不存在那么會根據ActionForm的完成路徑采用反射進行創建,再將創建好的ActionForm放到request或session中,之后返回ActionForm。

具體我們可以跟隨斷點調試來看看這個方法是如何運行的。

先設置斷點,之后進入processActionForm方法。

第一個步驟就是創建ActionForm:

// Create (if necessary) a formbean to use 
 
    ActionForm instance = RequestUtils.createActionForm 
 
      (request, mapping, moduleConfig, servlet); 
 
    if (instance == null) { 
 
      return (null); 
 
    } 

通過調用RequestUtils.createActionForm的方法把ActionMapping中的ActionForm字符串生成對象,并且返回。進入這段代碼中:

publicstaticActionForm createActionForm( 
 
      HttpServletRequest request, 
 
      ActionMapping mapping, 
 
      ModuleConfig moduleConfig, 
 
      ActionServlet servlet) { 
 
  
 
    // Is there a form bean associated with this mapping? 
 
    String attribute = mappinggetAttribute(); 
 
    if (attribute == null) { 
 
      return (null); 
 
    } 
 
  
 
    // Look up the form bean configuration information to use 
 
    String name = mapping.getName(); 
 
    FormBeanConfig config =moduleConfigfindFormBeanConfig(name); 
 
    if (config == null) { 
 
      log.warn("No FormBeanConfig found under '"+ name + "'"); 
 
      return (null); 
 
    } 
 
  
 
    ActionForm instance = lookupActionForm(request,attribute, mappinggetScope()); 
 
  
 
    // Can we recycle the existing form bean instance (if there is one)? 
 
    try { 
 
      if (instance != null && canReuseActionForm(instance,config)) { 
 
        return (instance); 
 
      } 
 
    } catch(ClassNotFoundException e) { 
 
      log.error(servlet.getInternal().getMessage("formBean",config.getType()), e); 
 
      return (null); 
 
    } 
 
  
 
    return createActionForm(config,servlet); 
 
} 
   

方法首先定義變量name,并且從mapping中獲取值,String name = mapping.getName();也就是我們實例中的LoginForm字符串。之后通過調用FormBeanConfig config =moduleConfig.findFormBeanConfig(name);這句話把相應的LoginForm字符串生成相應的對象。

這里要說明的是我們在struts-config配置文件中,配置過這樣一個標簽信息:

 
 
     
 
   

這個標簽在服務器一啟動的時候就會利用digester讀取這里的配置信息,并且放在FormBeanConfig類中,這樣我們可以通過上面那一句話就可以把LoginForm字符串生成相應的對象。

之后調用了ActionForm instance = lookupActionForm(request,attribute, mapping.getScope());這個方法,這個方法主要是查找scope屬性中有沒有存在ActionForm。具體實現:

if ("request".equals(scope)){ 
 
      instance = (ActionForm)request.getAttribute(attribute); 
 
    } else { 
 
      session = request.getSession(); 
 
      instance = (ActionForm)session.getAttribute(attribute); 
 
    } 

這里判斷scope屬性值是否為request,如果是則從request中讀出ActionForm,如果不是則從session中讀出。程序如果是第一次執行,那么ActionForm會是為空的。因為這里的ActionForm為空,所以就進入了if判斷語句中,最后通過調用return createActionForm(config, servlet);創建ActionForm并且返回。

之后processActionForm就會把返回來的ActionForm放入request或者session中。具體實現就是:

if ("request".equals(mapping.getScope())){ 
 
      request.setAttribute(mapping.getAttribute(), instance); 
 
    } else { 
 
      HttpSession session =request.getSession(); 
 
      session.setAttribute(mapping.getAttribute(), instance); 
 
    } 

到此為止,ActionForm就創建完成,當ActionForm創建完成之后,就要用其他的方法來往ActionForm中賦值了

上述就是小編為大家分享的如何在Struts1中使用ActionMapping了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創新互聯行業資訊頻道。


網頁名稱:如何在Struts1中使用ActionMapping
本文路徑:http://www.xueling.net.cn/article/jsjidj.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 国产精品一级无遮挡毛片 | 国产久热精品 | 97综合视频 | 国产精品久久一区性色av图片 | 久久久久激情 | 亚洲午夜无码AV毛片久久 | 福利视频一二三在线视频免费观看 | 亚洲第一成人无码A片 | 男人操女人视频免费观看 | 色就色欧美综合网站 | av无码一区二区三区午夜 | 中文字幕亚洲高清 | 欧美乱妇狂野欧美在线视频 | 国产综合久 | 欧美精品一区二区视频 | 一区二区不卡免费视频 | 欧美国产激情一区二区三区蜜月 | 久久久免费观看视频 | 亚洲精品乱码久久久一二三 | 永久91嫩草亚洲精品人人 | 伊人365影院 | 一级女毛片 | 福利视频三区 | 97超碰caoporen公开人人爽 | 国产成人av在线 | 亚洲人成欧美中文字幕 | 成人性生交大片免费看5 | 亚洲精品中文在线观看 | 性色一区二区三区 | 亚洲色一区二区三区四区 | 久久不见久久见中文字幕免费 | 99欧美日本一区二区留学生 | 女神异闻录5在线观看 | 国产成人片一区在线观看 | 日韩精品一区二区中文字幕无码 | 欧美日p视频| 91av视频免费在线?看 | 中文字幕日韩一区二区 | 男人的网站你懂得 | 色玖玖综合 | 国产亚洲美女精品久久久2020 |