美文网首页
struts2 action result 指定返回状态码5xx

struts2 action result 指定返回状态码5xx

作者: 金声玉振 | 来源:发表于2015-06-15 16:29 被阅读643次

为监控宝提供一个可访问数据库的api,当数据库连接失败时通过http响应返回错误状态码,而不是在消息体中显示5xx。

先写好一个简单的数据库访问action,当action发生错误时,指定http header中的返回码,需要在xml中写:

<result type="httpheader"><param name="status">500</param></result>

在探索这句话的过程中,学到了更多的关于struts2配置文件的细节,详见

http://zhou137520.iteye.com/blog/1564000

另外,struts2 result type除了常见的json、xml还有很多种,详见

http://www.cnblogs.com/laj12347/archive/2013/04/27/3046874.html

相关文章

网友评论

      本文标题:struts2 action result 指定返回状态码5xx

      本文链接:https://www.haomeiwen.com/subject/ebfsqttx.html