WebWork配置筆記
在標(biāo)簽方面,WebWork配置這幾個(gè)標(biāo)簽是有嚴(yán)格順序的,正確順序如下:
- 先〈result-types〉,必須有〈result-type/〉項(xiàng);
- 再〈interceptors〉,必須有〈interceptor/〉項(xiàng);
- 接下來是〈default-interceptor-ref name="completeStack"〉
- default-interceptor-ref〉;
- 然后是〈global-results〉,必須有〈result/〉項(xiàng);
- 然后〈global-exception-mappings〉,
- 子項(xiàng)如〈exception-mapping result="errorPage"
- exception="java.lang.Exception"/〉
- ***才是〈action/〉
***才是
- 〈action name="test" 〉
- 〈interceptor-ref name="exception"/ 〉
- 〈interceptor-ref name="basicStack"/ 〉
- 〈exception-mapping exception="com.acme.
- CustomException" result="custom_error"/ 〉
- 〈result name="custom_error" 〉custom_error.ftlresult 〉
- 〈result name="success" type="freemarker" 〉test.ftlresult 〉
- action 〉
webwork運(yùn)行流程:
默認(rèn)執(zhí)行execute()方法,該方法默認(rèn)返回SUCCESS;
- 〈Script language="JavaScript" src="/js/pagenumber.js" 〉
- 〈/Script 〉
- 〈script Language="JavaScript" 〉
- listNumUrl("courseInfoList.action?&pageNum="
- ,${pageNum},${allPageNum});
- 〈/script 〉
Ognl工作原理:
OgnlValueStack stack=new OgnlValueStack();
stack.push(new User())://首先將打算賦值的對(duì)象壓入棧中
stack.setValue("name","erica");//為棧頂對(duì)象User指定的屬性名name賦值
HttpSession是一個(gè)接口,
Properties實(shí)現(xiàn)了繼承了HashTable(實(shí)現(xiàn)了Map接口),也就是說它保存的也是值-鍵對(duì)象,它的setProperty("name","value")實(shí)質(zhì)上就是保存到HashTable里了。
- 〈action name="itemPersonalInput"
- class="cn.com.s520.course.ItemPersonalInputAction"〉
- 〈interceptor-ref name="fileUpload"〉
- 〈param name="allowedTypes"〉
- application/msword,image/gif,
- image/jpeg,image/pjpeg,application/x-shockwave-flash
- param〉
- 〈param name="maximumSize">10485760param〉
- interceptor-ref〉
- 〈interceptor-ref name="basicStack"/〉
- 〈result name="input" type="freemarker">
- /course/ItemPersonalInput.ftlresult〉
- 〈result name="error" type="freemarker">
- course/ItemPersonalInput.ftlresult〉
- 〈result name="success" type="redirect">
- /itemPersonalList.actionresult〉
- action〉
private File images;
private String imagesContentType;
private String imagesFileName;//得到不含路徑的文件名,如test.jpg
- 〈result name="success" type="stream" 〉
- 〈param name="contentType">image/jpegparam 〉
- 〈param name="inputName">imageStreamparam 〉
- 〈param name="
- contentDisposition">filename="logo.png"param 〉
- 〈param name="bufferSize">4096param 〉
- result>
1,〈param name="contentType">application/x-msdownloadparam 〉
contentType設(shè)成 application/x-msdownload 就可以。這樣瀏覽器會(huì)保證彈出一個(gè)下載文件的對(duì)話框。
2,inputName 這個(gè)比較重要,這個(gè)名字是輸入流的名稱, 以后要steam result的實(shí)現(xiàn)類中為根據(jù)OGNL的表達(dá)式去查找的。
contentDisposition 這個(gè)是下載之后,保存在用戶端的文件名稱。
3,另外一個(gè)參數(shù):contentLength就是下載文件的大小,webwork的stream result似乎實(shí)現(xiàn)有問題,不能根據(jù)文件的大小動(dòng)態(tài)進(jìn)行設(shè)置,只能寫死。
這個(gè)WebWork配置參數(shù)的意義是告訴瀏覽下載的文件有多大,以便瀏覽器正確的顯示進(jìn)度條。如果這個(gè)功能很重要的話,可以重新寫一個(gè)RESULT來實(shí)現(xiàn)。
- 〈result>/form.jspresult>如果不指明,默認(rèn)為success
- 〈action name="userReg"
- class="com.opensymphony.xwork.ActionSupport" 〉
- 〈result name="input">/app/userreg.ftlresult 〉
- 〈/action 〉
這里將不會(huì)出現(xiàn)預(yù)期的頁面,因?yàn)槟J(rèn)為success,不會(huì)轉(zhuǎn)向我們指定的input頁面
- 〈result name="no-content" type="header"〉
- 〈param name="status"〉204param〉
- 〈param name="headers.customHeaderA"〉A(chǔ)param〉
- 〈param name="headers.customHeaderB"〉Bparam〉
- result〉
chain視圖:
同一個(gè)包里,可設(shè)置type為chain,對(duì)應(yīng)action的擴(kuò)展名也可以不寫,
- 〈result name="error" type="chain"〉
- 〈param name="actionName"〉barparam〉
- result〉
不同包里
- 〈result name="errorPage" type="chain" 〉
- 〈param name="namespace" 〉/param 〉
- 〈param name="actionName" 〉barparam 〉
- result 〉
或者設(shè)置type為redirect,重定向過去
- 〈action name="index" class="
- com.opensymphony.xwork.ActionSupport"〉
- 〈result name="success" type="redirect"〉
- /course/courseInfoList.actionresult〉
- action〉
- 〈default-interceptor-ref name="defaultStack"/〉
這里只是在你沒有設(shè)置攔截器時(shí)才用到,如果WebWork配置攔截器了,就不會(huì)調(diào)用這個(gè)了。
【編輯推薦】