當前位置:首頁 » 操作系統 » struts項目源碼

struts項目源碼

發布時間: 2022-12-31 07:38:05

A. 怎麼把struts2源碼導入到eclipse

方法如下:
右擊project,選擇 Build Path --> Add External Archives.. 選擇lib所在目錄。
建議建立一個UserLib:Windows -- java -- Build Path -- User Libraries ,在右邊點擊New,新建一個名為struts2的lib name, 然後點擊Add Jars,把對應的jar包導入進去。
使用UserLib:右擊項目,Add Library -- User Library -- 選擇建的struts2的lib就Ok了。

B. 我想研究一下struts2源碼,該怎麼做

我前幾天也跟你有一樣的想法,研究了一下struts2的源碼。
建一個空白的web工程(myeclipse),正確引入struts2的jar。做個最簡單的例子跑通就行。
struts2的源碼主要是struts2-core-2.xxx.jar和xwork-core-2.xxxx.jar 將這兩個jar與源碼包關聯就可以了。這樣可以看到源碼了。
而且如果你想測試某個類,可以自己在自己的工程了建於struts2同名的包復制源碼,加上自己的測試代碼,跑起來會引用你寫的,而其他的類則會去struts2的包類引用。
開始有點亂,看了三四天才整出點頭緒,祝你好運!

C. Struts源碼研究 - Action-Input屬性篇

初學Struts 寫了一個很簡單的應用 主要功能和頁面如下 首頁顯示一個 添加新用戶 的鏈接 點擊該鏈接出發一個forward動作 頁面導向到添加用戶的jsp頁面 添加用戶的jsp頁面中 可供用戶輸入 用戶名 和 用戶描述 兩項 用戶輸入完畢 將做輸入數據合法性檢查 檢查通過 將輸入信息保存進入文件(使用了Properties類) 然後返回首頁 檢查失敗返回添加用戶頁面 數據合法性檢查分成兩塊 第一部分檢查條件使用Struts的Validator 檢查條件配置在Validator xml中 第二部分檢查放在ActionForm中 檢查失敗將錯誤信息置入ActionErrors中 然後返回到添加用戶的頁面並顯示錯誤信息 JSP頁面 ActionForm和Action類的代碼書寫都參照了struts example應用 所以這里代碼不再列舉 請看附件中的代碼包這里值得一提的是 在開發過程中 碰到了一個小問題 正是由於該問題 才導致查看Struts源碼 刨根問底的查找錯誤原因的過程該錯誤發生在Struts的配置文件中 首先將錯誤的配置文件列出如下 <?xml version= encoding= ISO ?><!DOCTYPE struts config PUBLIC //Apache Sofare Foundation//DTD Struts Configuration //EN config_ _ dtd ><struts config><! ======================================== Form Bean Definitions ><form beans><form beanname= CreateUserForm type= zchome CreateUserForm /></form beans><! ================================= Global Exception Definitions ><global exceptions></global exceptions><! =================================== Global Forward Definitions ><global forwards><! Default forward to Wele action ><! Demonstrates using index jsp to forward ><forward name= wele path= /Wele do /></global forwards><! =================================== Action Mapping Definitions ><action mappings><! Default Wele action ><! Forwards to Wele jsp ><actionpath= /Wele type= apache struts actions ForwardAction parameter= /jsp/Wele jsp /><action path= /createuserpage forward= /jsp/createuser jsp ></action><actionpath= /docreateuser type= zchome CreateUserAction name= CreateUserForm scope= request input= createuser ><forward name= createusersuccess path= /jsp/Wele jsp /><forward name= createuser path= /jsp/createuser jsp /></action></action mappings><! ===================================== Controller Configuration ><controller><set property property= processorClass value= apache struts tiles TilesRequestProcessor /></controller><! ================================ Message Resources Definitions ><message resources parameter= resources application /><! ======================================= Plug Ins Configuration ><! ========== Tiles plugin =================== ><! ><! This plugin initialize Tiles definition factory This later can takes someparameters explained here after The plugin first read parameters from web xml thenoverload them with parameters defined here All parameters are optional The plugin should be declared in each struts config file definitions config: (optional)Specify configuration file names There can be several maseparated file names (default: ?? ) moleAware: (optional struts )Specify if the Tiles definition factory is mole aware If true (default) there will be one factory for each Struts mole If false there will be one mon factory for all mole In this later case it is still needed to declare one plugin per mole The factory will beinitialized with parameters found in the first initialized plugin (generally theone associated with the default mole) true : One factory per mole (default)false : one single shared factory for all moles definitions parser validate: (optional)Specify if xml parser should validate the Tiles configuration file true : validate DTD should be specified in file header (default)false : no validationPaths found in Tiles definitions are relative to the main context ><! ment following if struts x ><plug in className= apache struts tiles TilesPlugin ><set property property= definitions config value= /WEB INF/tiles defs xml /><set property property= moleAware value= true /><set property property= definitions parser validate value= true /></plug in><! end ment if struts x ><plug in className= apache struts validator ValidatorPlugIn ><set propertyproperty= pathnames value= /WEB INF/validator rules xml /WEB INF/validation xml /></plug in></struts config>首先描述一下系統的出錯背景 從首頁點擊鏈接來到添加用戶的頁面 正常 在添加用戶頁面中輸入Vlidator xml文件中定義的錯誤數據 彈出Javascript對話框 提示出錯 正常 在添加用戶頁面中輸入合法數據 數據保存進入文件並重定向到首頁 正常 在添加用戶頁面中輸入ActionForm中定義的非法數據 系統應返回到添加用戶的頁面 出錯!!!OK 來著重看這個添加動作的定義 如下 <actionpath= /docreateuser type= zchome CreateUserAction name= CreateUserForm scope= request input= createuser ><forward name= createusersuccess path= /jsp/Wele jsp /><forward name= createuser path= /jsp/createuser jsp /></action>從以上的定義可以看出 如果Validate驗證出錯 Struts應該為我們重定向到input域所定義的uri 即/jsp/createuser jsp看起來應該沒有問題 再來看看出錯信息 如下 java lang IllegalArgumentException: Path createuser does not start with a / characterat re ApplicationContext getRequestDispatcher(ApplicationContext java: )at re ApplicationContextFacade getRequestDispatcher(ApplicationContextFacade java: )at apache struts action RequestProcessor doForward(RequestProcessor java: )at apache struts tiles TilesRequestProcessor doForward(TilesRequestProcessor java: )at apache struts action RequestProcessor internalMoleRelativeForward(RequestProcessor java: )at apache struts tiles TilesRequestProcessor internalMoleRelativeForward(TilesRequestProcessor java: )at apache struts action RequestProcessor processValidate(RequestProcessor java: )at apache struts action RequestProcessor process(RequestProcessor java: )at apache struts action ActionServlet process(ActionServlet java: )at apache struts action ActionServlet doPost(ActionServlet java: )出錯信息清楚的說明 createuser 這個path應該以 / 字元開頭為定位這個錯誤 從以上錯誤信息 開始打開Struts的源碼RequestProcessor java進行研究 首先來到這一段 public class RequestProcessor {protected boolean processValidate(H lishixin/Article/program/Java/ky/201311/28659

D. 怎樣將struts2的源碼關聯到myeclipse中

簡單設置一下就能實現了。這里有篇文章,是以在eclipse中查閱struts2的源代碼為例,圖文詳解,希望對樓主有所幫助,myeclipse同樣適用。文章地址:http://jingyan..com/article/454316ab596470f7a7c03aab.html怎樣在Eclipse中快速查看各種源代碼?

E. Struts2中關於xwork和OGNL的源代碼下載

還有cvs干嗎,怎麼不用svn來checkout呀。

F. Struts2增刪改查(完整項目版+源碼+資料庫)

ajax的ok不

G. Struts源碼研究 - html-Link標簽篇

Struts里的:Cancel標簽是在Form中經常運用的一個標簽 主要功能就是cancel當前Form 一般寫法如下 ===========================<:cancel><bean:message key= createuser cancelbutton /></:cancel>===========================這個標簽將生成如下的HTML代碼 <input type= submit name= apacl CANCEL value= 返回 onclick= bCancel=true; >bCancel=true是一段javascript bCancel是在使用Struts的Validator時 Struts自動為我們加的一段Javascript代碼里的一個變數這段Javascript簡略摘要如下 ===========================<script type= text/javascript language= Javascript ><! Beginvar bCancel = false;function validateCreateUserForm(form) {if (bCancel)return true;elsereturn validateMaxLength(form) && validateRequired(form) && validateMinLength(form);}===========================由上可以看到 這個bCancel=true時 Javascript將自動將表單提交(return true) 也就是說 如果我們在後台Action的代碼里沒有對這個Cancel動作寫特定代碼的話 這個Cancel標簽產生的效果和submit按鈕產生的動作完全一致!!(因為這個按鈕的type也等於submit)這一點需要非常的注意!所以 一般來說 我們在Action類的execute方法裡面會加上如下的一段代碼來處理這個Cancel動作 ===========================// Was this transaction cancelled?if (isCancelled(request)) {return (mapping findForward( createusersuccess ));}===========================有了以上的代碼 Cancel動作就有了相應的處理代碼 轉到相關的頁面了 本來事情已經解決 但本著對Struts源碼研究的精神 我們還需要對以上代碼研究一下OK 讓我們來看一下isCancelled這個方法在什麼地方被定義了 內容是什麼?首先發現 這個方法被定義在Action類裡面 代碼如下 ===========================/*** <p>Returns <code>true</code> if the current form s cancel button was* pressed This method will check if the <code>Globals CANCEL_KEY</code>* request attribute has been set which normally occurs if the cancel* button generated by <strong>CancelTag</strong> was pressed by the user* in the current request If <code>true</code> validation performed* by an <strong>ActionForm</strong> s <code>validate()</code> method* will have been skipped by the controller servlet </p>** @param request The servlet request we are processing* @see apacl CancelTag*/protected boolean isCancelled(HttpServletRequest request) {return (request getAttribute(Globals CANCEL_KEY) != null);}===========================哦 原來是在request對象中查找Globals CANCEL_KEY這個key值是否綁定了一個對象 如果是 那麼就代表按下Cancel按鈕後 Struts會在request對象中綁定一個對象 並以這個key值來命名那Struts是在什麼地方綁定了這個對象呢?很自然的 讓我們從頭找起從ActionServlet的process方法開始找起 歷經多次方法調用 終於找到了根源 原來是在RequestProcessor java中 代碼如下 ===========================/*** <p>Process an <code>HttpServletRequest</code> and create the* corresponding <code>HttpServletResponse</code> </p>** @param request The servlet request we are processing* @param response The servlet response we are creating** @exception IOException if an input/output error occurs* @exception ServletException if a processing exception occurs*/public void process(HttpServletRequest request HttpServletResponse response)throws IOException ServletException {//省略代碼若干// Process any ActionForm bean related to this requestActionForm form = processActionForm(request response mapping);//答案就在這個processPopulate方法中processPopulate(request response form mapping);if (!processValidate(request response form mapping)) {return;}/*** Populate the properties of the specified ActionForm instance from* the request parameters included with this request In addition * request attribute <code>Globals CANCEL_KEY</code> will be set if* the request was submitted with a button created by* <code>CancelTag</code> ** @param request The servlet request we are processing* @param response The servlet response we are creating* @param form The ActionForm instance we are populating* @param mapping The ActionMapping we are using** @exception ServletException if thrown by RequestUtils populate()*/protected void processPopulate(HttpServletRequest request HttpServletResponse response ActionForm form ActionMapping mapping)throws ServletException {if (form == null) {return;}// Populate the bean properties of this ActionForm instanceif (log isDebugEnabled()) {log debug( Populating bean properties from this request );}form setServlet(this servlet);form reset(mapping request);if (mapping getMultipartClass() != null) {request setAttribute(Globals MULTIPART_KEY mapping getMultipartClass());}RequestUtils populate(form mapping getPrefix() mapping getSuffix() request);// Set the cancellation request attribute if appropriateif ((request getParameter(Constants CANCEL_PROPERTY) != null) ||(request getParameter(Constants CANCEL_PROPERTY_X) != null)) {request setAttribute(Globals CANCEL_KEY Boolean TRUE);}}===========================OK 看最後幾行代碼 Struts從request中取得Constants CANCEL_PROPERTY這個參數 如果這個參數不為空 那麼他就將TRUE這個對象以Globals CANCEL_KEY為key值 放到了request對象中至於這個Constants CANCEL_PROPERTY這個值是什麼 現在都可以猜到了 顯然就是:Cancel這個標簽生成的HTML代碼中 Cancel這個按鈕的名稱嘛!查了一下 果然是 <input type= submit name= apacl CANCEL value= 返回 onclick= bCancel=true; >而Constants CANCEL_PROPERTY這個值就是 apacl CANCEL lishixin/Article/program/Java/ky/201311/28930

熱點內容
隨機啟動腳本 發布:2025-07-05 16:10:30 瀏覽:535
微博資料庫設計 發布:2025-07-05 15:30:55 瀏覽:32
linux485 發布:2025-07-05 14:38:28 瀏覽:310
php用的軟體 發布:2025-07-05 14:06:22 瀏覽:760
沒有許可權訪問計算機 發布:2025-07-05 13:29:11 瀏覽:437
javaweb開發教程視頻教程 發布:2025-07-05 13:24:41 瀏覽:735
康師傅控流腳本破解 發布:2025-07-05 13:17:27 瀏覽:249
java的開發流程 發布:2025-07-05 12:45:11 瀏覽:696
怎麼看內存卡配置 發布:2025-07-05 12:29:19 瀏覽:288
訪問學者英文個人簡歷 發布:2025-07-05 12:29:17 瀏覽:838