struts2學習筆記(2) 型別轉換 輸入校驗

2021-04-21 00:45:03 字數 554 閱讀 1609

struts2的型別轉換機制

涉及到的檔案 

ognl.defaulttypeconverter

org.apache.struts2.util.strutstypeconverter

配置檔案

區域性配置檔案寫在相應的action檔案目錄下面,配置檔案名稱必須是action的類檔名+"-conversion.properties"

全域性配置檔案寫在src目錄下面的xwork-conversion.properties裡面

配置檔案的內容就是 要轉換的類=實現轉換的類名

struts2輸入校驗

遇到型別轉換錯誤的時候(也就是說不能進行型別轉換),struts2框架自動生成一條錯誤資訊,並且將該錯誤資訊放到addfielderror裡面

型別轉換與輸入校驗的流程

1. 首先struts2對客戶端傳來的資料進行型別轉換

2. 型別轉換完畢後再進行輸入校驗

3. 如果型別轉換和輸入校驗都沒有錯誤發生,那麼進入execute方法(呼叫商業邏輯)

注意:如果型別轉換不成功,也同樣要進行輸入校驗

struts2 型別轉換

繼承strutstypeconverter 類或者直接去實現 ognl.defaulttypeconverter 類 strutstypeconverter 類是對defaulttypeconverter 類的包裝。實現 convertfromstring 和converttostring 方法 然...

struts2型別轉換

一 內容提要 1.型別轉換概述 2.型別轉換出錯時如何進行處理 轉到哪個頁面 顯示什麼錯誤訊息 3.自定義型別轉換器 4.型別轉換與複雜物件配合使用 二 型別轉換概述 從乙個html表單到乙個action物件,型別轉換是從字串到非字串http沒有 型別 的概念,每一項表單輸入只可能是乙個字串或乙個字...

Struts2型別轉換

實體類 public class user struts.xml配置 struts型別轉換的api struts2的型別轉換器實際上是基於ognl實現的,在ognl專案中有乙個ognl.typeconverter介面,這個介面就是實現型別轉換器必須實現的介面。該介面定義如下 public inte ...