Posted on 2007-02-26 10:23
lixw 閱讀(603)
評論(2) 編輯 收藏
1、在Action中獲得Servlet API中的對象:
1?com.opensymphony.xwork2.ActionContext?context?=?ActionContext.getContext();
2?HttpServletRequest?request?=?org.apache.struts2.ServletActionContext.getRequest();
3?HttpServletResponse?response?=?org.apache.struts2.ServletActionContext.getResponse();
4?HttpSession?session?=?request.getSession();
??? 獲取與Servlet運行環境無關的Session集合:
Map?sessionMap?=?ActionContext.getContext().getSession();
??? IOC方式訪問,可以通過實現ServletRequestAware、ServletResponseAware和
SessionAware。
參考
WebWork API。
2、自定義Action調用方法:
- 在struts.xml的action配置中,增加屬性method="aliasMethod";
- 在訪問Action的URL中增加!aliasMethod.action,形如 http://localhost:8080/app/ActionName!aliasMethod.action。
3、自己布局form:
??? 給<s:form />增加屬性theme="simple"。
4、WebWork中的特殊命名對象:
??? #prameters['foo'] or #parameters.foo??????????? ??? request.getParameter("foo");
??? #request['foo'] or #request.foo?? ?? ?? ?? ?? ?? ?? request.getAttribute("foo");
??? #session['foo'] or #session.foo?? ?? ?? ?? ?? ?? ?? session.getAttribute("foo");
??? #application['foo'] or #application.foo?? ?? ?? ??? application.getAttribute("foo");
??? #attr['foo'] or #attr.foo?? ?? ?? ?? ?? ?? ?? ?? ?? pageContext.getAttribute("foo");
??