StrutsResultSupport的利用详解编程语言
在有非凡情形时;假如没有异常信息,然则有错误而且有错误信息等内容;此时也需要进行友爱的错误处置惩罚的话,那么可以借助StrutsResultSupport 返回效果类型来实现特定处置惩罚。此种体式格局先需要继续StrutsResultSupport ,然后可以在子类中获取本次请求的相关信息,再凭据相关信息进行效果处置惩罚:
package commons.struts2; import a href="http://lib.csdn.net/base/java" title="Java 常识库" target=_blank Java /a .io.PrintWriter; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.dispatcher.StrutsResultSupport; import com.opensymphony.xwork2.ActionInvocation; * result type for output string in action * @author songwei,yaolei b Example: /b ** !-- START SNIPPET: example -- * result name="success" type="string" * param name="stringName" stringName /param * /result * !-- END SNIPPET: example -- **
*/
public class StringResultType extends StrutsResultSupport {
private static final long serialVersionUID = 1L;
private String contentTypeName;
private String stringName = "";
public StringResultType() {
super();
}
public StringResultType(String location) {
super(location);
}
protected void doExecute(String finalLocation, ActionInvocation invocation)
throws Exception {
HttpServletResponse response = (HttpServletResponse) invocation
.getInvocationContext().get(HTTP_RESPONSE);
// String contentType = (String)
// invocation.getStack().findValue(conditionalParse(contentTypeName,
// invocation));
String contentType = conditionalParse(contentTypeName, invocation);
if (contentType == null) {
contentType = "text/plain; charset=UTF-8";
}
response.setContentType(contentType);
PrintWriter out = response.getWriter();
// String result = conditionalParse(stringName, invocation);
String result = (String) invocation.getStack().findValue(stringName);
out.println(result);
out.flush();
out.close();
}
public String getContentTypeName() {
return contentTypeName;
}
public void setContentTypeName(String contentTypeName) {
this.contentTypeName = contentTypeName;
}
public String getStringName() {
return stringName;
}
public void setStringName(String stringName) {
this.stringName = stringName;
}
}
package test; import com.opensymphony.xwork2.ActionSupport; public class MyAction extends ActionSupport{ String result="abc"; public String ajax() { return "ajaxResponse"; // getter setter public String getResult() { return result; public void setResult(String result) { this.result = result; }
!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd" struts package name="test" extends="struts-default" result-types result-type name="string" /result-type /result-types action name="myAction" result name="ajaxResponse" type="string" param name="stringName" result /param /result /action /package /struts
这里界说返回Action的String result变量,即“abc”。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/11694.html
cjavaxml相关文章
- css实现一款漂亮的查询框详解编程语言
- 利用Cookie防止刷新的在线考试倒计时JS代码详解编程语言
- 简单实用的时间处理Java工具类DateUtil详解编程语言
- java利用jnotify监视目录变化详解编程语言
- 利用iText导出pdf文件代码详解编程语言
- 利用Java Mail发送邮件的代码详解编程语言
- 利用barcode4j生成条形码详解编程语言
- 根据URL抓取并生成缩略图的Java代码详解编程语言
- 利用注解将JDBC结果集转成Java对象详解编程语言
- Struts2自界说效果视图(servlet验证码)详解编程语言
- 删除或修改本地Git账号密码详解编程语言
- js给redio设置哪一个被选中详解编程语言
- javascript中两种基本常用排序算法分析详解编程语言
- python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件详解编程语言
- php-fpm开启报错-ERROR: An another FPM instance seems to already listen on /tmp/php-cgi.sock详解编程语言
- CSS 之 Opacity多浏览器透明度兼容处理详解编程语言
- 谈谈php依赖注入和控制反转详解编程语言
- ABAP-JSON数据格式互转详解编程语言
- 创建PO详解编程语言
- 利用python实现微信小程序游戏跳一跳详细教程详解编程语言
- php imagick 文字居中的方法详解编程语言
- ladon的jsonwsp文件parse_description方法报types未定义错误解决办法详解编程语言
- Python编程小技巧(一)详解编程语言
- Explain About The PO Confirmation Control Key In Detail–采购订单中的确认控制详解编程语言
- abap中利用BINARY SEARCH 二分法查找内表记录时注意项详解编程语言
- ABAP–如何建立通过sap表维护工具来维护自定义表TCODE详解编程语言
- STMS – XT216 – 1 of 1 requests do not match the component version of the target system – XT 216详解编程语言