public FBSContext build() throws Exception {
log.debug("FBS Build Context!");
// 构建context对象
FBSContext context = new FBSContext();
FBSContext.setContext(context);
try {
// 将request Parameter中的参数存入context
log.debug("FBS put Request Paramters to Context!");
for (Enumeration<String> paramNames = getHttpRequest()
.getParameterNames(); paramNames.hasMoreElements();) {
String name = paramNames.nextElement();
context.putParamter(name, getHttpRequest().getParameter(name));
}
// 将request Attribute中的参数存入context
log.debug("FBS put Request Attribute to Context!");
for (Enumeration<String> attributeNames = getHttpRequest()
.getAttributeNames(); attributeNames.hasMoreElements();) {
String name = attributeNames.nextElement();
context.putParamter(name, getHttpRequest().getAttribute(name));
}
// 将HttpRequest对象和HttpResponse对象存入Context
log.debug("FBS put Request to Context!");
context.putParamter(FBSContext.HTTP_REQUEST, getHttpRequest());
log.debug("FBS put Response to Context!");
context.putParamter(FBSContext.HTTP_RESPONSE, getHttpResponse());
} catch (FBSContextException e) {
log.error("FBS web http context build error!");
throw e;
}
return context;
}
structs2方法
Map<String, Object> map = ActionContext.getContext()
.getParameters();// ActionContext.getContext().getContextMap();
if (map != null && map.size() > 0) {
Set<String> keySet = map.keySet();
for (Iterator<String> iterator = keySet.iterator(); iterator
.hasNext();) {
String key = iterator.next();
if (key != null && map.get(key) != null) {
context.putParamter(key, map.get(key));
}
}
}
log.debug("FBS Build Context!");
// 构建context对象
FBSContext context = new FBSContext();
FBSContext.setContext(context);
try {
// 将request Parameter中的参数存入context
log.debug("FBS put Request Paramters to Context!");
for (Enumeration<String> paramNames = getHttpRequest()
.getParameterNames(); paramNames.hasMoreElements();) {
String name = paramNames.nextElement();
context.putParamter(name, getHttpRequest().getParameter(name));
}
// 将request Attribute中的参数存入context
log.debug("FBS put Request Attribute to Context!");
for (Enumeration<String> attributeNames = getHttpRequest()
.getAttributeNames(); attributeNames.hasMoreElements();) {
String name = attributeNames.nextElement();
context.putParamter(name, getHttpRequest().getAttribute(name));
}
// 将HttpRequest对象和HttpResponse对象存入Context
log.debug("FBS put Request to Context!");
context.putParamter(FBSContext.HTTP_REQUEST, getHttpRequest());
log.debug("FBS put Response to Context!");
context.putParamter(FBSContext.HTTP_RESPONSE, getHttpResponse());
} catch (FBSContextException e) {
log.error("FBS web http context build error!");
throw e;
}
return context;
}
structs2方法
Map<String, Object> map = ActionContext.getContext()
.getParameters();// ActionContext.getContext().getContextMap();
if (map != null && map.size() > 0) {
Set<String> keySet = map.keySet();
for (Iterator<String> iterator = keySet.iterator(); iterator
.hasNext();) {
String key = iterator.next();
if (key != null && map.get(key) != null) {
context.putParamter(key, map.get(key));
}
}
}