Map attibutes = ActionContext.getContext().getSession();1.date
private static DateFormat DF = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
2.在页面显示日期:
<s:date name="#myDate.now" format="yyyy/MM/dd hh:mm:ss" />(struts2) myDate是Action,now是属性
<s:date name="#myDate.future" nice="true"/
2. <s:iterator value="new int[3]" status="stat">
3.List<OperationsEnum> list= Arrays.asList(OperationsEnum.values());
4.在页面中调用一个方法:(这个方法在Action中。由action转发到的页面)
<s:checkboxlist label="Operations"
name="selectedOperations"
list="%{availableOperations}" //getAvailableOperations这个是action里的方法,获取list的值。
listKey="name()"
listValue="name()"
/>
5 String str = String.format("%04d", youNumber);
---------------------------
6 struts2: HttpSession se=ServletActionContext.getRequest().getSession();
7.Map attibutes = ActionContext.getContext().getSession(); 它里面的值和session中的值相同(ThreadLocal)
8.Map<String, ResultConfig> resultsMap = invocation.getProxy().getConfig().getResults();
//在自定义的interceptor中获取result
9.invocation.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation invocation, String resultCode) {
Map resultsMap = invocation.getProxy().getConfig().getResults();
ResultConfig finalResultConfig = (ResultConfig)resultsMap.get(resultCode);
System.out.println(finalResultConfig.getName());
// do something interesting with the 'to-be' executed result
}
});
10.7.How can we force the Action Mappings (struts.xml) to reload
devMode=true或者struts.configuration.xml.reload=true
11.运行时获取request
HttpServletRequest request = ServletActionContext.getRequest();
或者实现ServletRequestAware并且加入servlet-config拦截器.
13.获取提交的request parameters
Map parameters = ActionContext.getContext().getParameters();
实现ParameterAware并且加入servlet-config拦截器
12.运行时获取response
HttpServletResponse response = ServletActionContext.getResponse()
或者实现ServletResponseAware并且加入servlet-config拦截器.
14.访问action配置中定义的参数
直接在action中定义对应action中参数名的settermethod,或者定义setParams(Map)来实现.
15.Prepare 拦截器最好在validation拦截器之前,否则可能被打断.
24.如何定义全局properties文件
struts.custom.i18n.resources=global-messages, image-messages
http://myoldman.iteye.com/blog/176670
29.为jsp页面添加jsp标签的支持
在web.xml中添加如下定义