-
struts2接受參數(shù)
1、使用Action的屬性接受參數(shù)
action類直接創(chuàng)建對象實現(xiàn)get/set
2、使用Domain的Model接受參數(shù)
//創(chuàng)建model對象 private?User?user;
//表單name修改 用戶名:<input?type="text"?name="username"> 密碼:<input?type="password"?name="password">
3、使用ModelDriven接受參數(shù)
實現(xiàn)ModelDriven<T>接口,指定泛型類型
//需要實例化 private?User?user=new?User(); @Override public?User?getModel()?{ ????return?user; }
對于List<String>對象需要
<input?type="text"?name="listbook[0]">
對于List<User>對象需要
<input?type="text"?name="listbook[0].username">
查看全部 -
//修改.action后綴 <constant?name="struts.action.extension"?value="html"></constant>
默認沒有配置后綴,其實不添加.acton后綴也可以訪問
//web.xml也可以配置修改后綴 <filter> ??<filter-name>struts2</filter-name> ??<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> ???<init-param> ?????<param-name>struts.action.extension</param-name> ?????<param-value>do</param-value> ???</init-param> </filter>
查看全部 -
默認action配置
注意需要注釋掉使用類名通配符的action配置,否則會去匹配類,報錯500
<default-action-ref?name="index"> </default-action-ref> <action?name="index"> ????<result>/error.jsp</result> </action>
查看全部 -
指定配置文件
<include?file="xml"></include>
查看全部 -
動態(tài)方法調(diào)用
動態(tài)方法調(diào)用就是為了解決一個Action對應(yīng)多個請求的處理,以免Action太多。
1、指定method屬性
<action?name="addaction"?method="add"?class="com.action.HelloWorldAction"> ????<result?name="success">/index.jsp</result> </action>
2、感嘆號方式
<constant?name="struts.enable.DynamicMethodInvocation"?value="true"></constant> //指定方法返回視圖 public?String?add(){ ????return?"add"; } //struts配置多個result,指定name對應(yīng)的 視圖名稱 <result>/index.jsp</result> <result?name="add">/index.jsp</result> <result?name="update">/update.jsp</result>
訪問方式:/helloworld!(方法名).action
3、通配符方式
<action?name="helloworld_*"?method="{1}"?class="com.action.HelloWorldAction"> ????<result>/index.jsp</result> ????<result?name="add">/{1}.jsp</result> ????<result?name="update">/{1}.jsp</result> </action> <action?name="*_*"?method="{2}"?class="com.action.{1}Action"> ????<result>/index.jsp</result> ????<result?name="add">/{2}.jsp</result> ????<result?name="update">/{2}.jsp</result> </action>
查看全部 -
Struts2的Action搜索順序
localhost:8080/struts/path1/path2/path3/student.action
第一步:判斷package是否存在,如:path1/path2/path3/
存在package
第二步:判斷action是否存在,不過不存在則去默認namespace的package里尋找action
第三步:如果沒有,則報錯
不存在package
第二步:檢查上一級路徑的package是否存在(直到默認namespace),重復第一步
第三步:如果沒有,則報錯
查看全部 -
1.Struts2訪問Servlet API方式
1、ActionContext
2、實現(xiàn)Aware接口
3、ServletActionContext
查看全部 -
struts.xml
struts的核心配置文件,在開發(fā)過程中利用率最高。
該文件主要負責管理應(yīng)用中的Action映射,以及該Action包含的Result定義等。
struts.properties
struts2框架的全局屬性文件,自動加載
該文件包含很多個key-value對
該文件可以配置在struts.xml文件中,使用constant元素。
查看全部 -
從客戶端發(fā)送請求過來,先經(jīng)過前端控制器(核心過濾器 StrutsPrepareAndExecuteFilter)過濾器中執(zhí)行一組攔截器(一組攔截器 就會完成部分功能代碼),到底哪些攔截器執(zhí)行了呢,在Struts2中定義很多攔截器,在其默認棧中的攔截器會得到執(zhí)行,這個我們可以通過斷點調(diào)試的方式測試,攔截器執(zhí)行完成后,就會執(zhí)行目標Action,在Action中返回一個結(jié)果視圖,根據(jù)Restult的配置進行頁面的跳轉(zhuǎn)。
查看全部 -
MVC模式
查看全部 -
result 的type屬性默認是dispacher
查看全部 -
struts2接收list參數(shù)
Action中定義List屬性:bookList
在jsp中使用name:bookList[0]的形式
查看全部 -
struts.properties的常用配置
查看全部 -
加后綴訪問,如.html,http://localhost:8080/HelloWord/helloWord.html
配置方式如下:
查看全部 -
默認Action的配置
用于配置找不到action時的錯誤頁面設(shè)置
查看全部
舉報