struts2学习Tips

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");

你可能感兴趣的:(apache,servlet,struts,IOC,Webwork)