可以在struts2-core-{version}.jar中找到struts-default.xml,里面列举了当前可以使用的所有result-type以及对应的class
此处是struts2.2.3的
view plaincopy to clipboardprint
1.chain
该类型是请求转发给其他的action,如果为jsp则会报错
需要注意的就是与redirect的区别,请求转发是还在当前请求,
而redirect会响应一次浏览器然后浏览器再根据响应请求重定向的资源,注意看url的变化就明白了!
下面是apache给的示例,这个比较简单,没什么说的,
view plaincopy to clipboardprint
dashboard
/secure
foo.jsp
3.httpheader这个挺有意思的,可以随便更改响应状态比如下面的这个示例view plaincopy to clipboardprint
400
/** The default parameter */
public static final String DEFAULT_PARAM = "status";
private boolean parse = true;
private Map
private int status = -1;
private int error = -1;
private String errorMessage;下面是具体执行操作过程,可以看到response.setStatus等操作view plaincopy to clipboardprint public void execute(ActionInvocation invocation) throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); ValueStack stack = ActionContext.getContext().getValueStack(); if (status != -1) { response.setStatus(status); } else if (error != -1) { if (errorMessage != null) { String finalMessage = parse TextParseUtil.translateVariables( errorMessage, stack) : errorMessage; response.sendError(error, finalMessage); } else response.sendError(error); } if (headers != null) { for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String value = (String) entry.getValue(); String finalValue = parse TextParseUtil.translateVariables(value, stack) : value; response.addHeader((String) entry.getKey(), finalValue); } } } public void execute(ActionInvocation invocation) throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
ValueStack stack = ActionContext.getContext().getVal