星空网 > 软件开发 > Java

SSH输入错误Action

在类型转化、输入验证校验 、文件上传等出错的时候,如Action中某个变量是int,而上传的值是"ABC",此时Action不会执行execute()函数,而是直接返回result name="input",如果没有定义result name="input"跳转的Action,就会报错误。可以自己定义一个Action,遇到此类情况时返回自己定义的信息。

首先定义输入错误Action类:

@SuppressWarnings("serial")public class InputErrorAction extends ActionSupport {      public String execute(){        int status;    Map<String, Object> map = new HashMap<String, Object>();    status = -1001;    map.put("Status", status);    map.put("Desc", "输入错误未通过验证");        // 返回结果    try{            ResUtil.toJson(ServletActionContext.getResponse(), map);    }catch (IOException e){      e.printStackTrace();    }        return null;  }}

在applicationContext.

  <!-- 输入错误 -->  <bean id="inputErrorAction" class="com.xkssh.action.InputErrorAction">  </bean>

在struts中定义一个Action:

    <!-- 输入错误未通过验证 -->    <action name="input_error" class="inputErrorAction">    </action>

为其他Action定义result name="input"时跳转的Action:

    <action name="xkgwc_delete" class="xkgwcDeleteAction">      <result name="success"/>      <result name="input" type="redirectAction">         <param name="actionName">input_error</param>       </result>    </action>

这样,当发生输入错误时,就会返回自己定义的信息:

SSH输入错误Action




原标题:SSH输入错误Action

关键词:SSH

SSH
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

马来西亚一件代发海外仓:https://www.goluckyvip.com/tag/92609.html
马来西亚海外仓代发:https://www.goluckyvip.com/tag/92611.html
马来西亚海外仓储:https://www.goluckyvip.com/tag/92613.html
越南马来西亚海外仓:https://www.goluckyvip.com/tag/92614.html
海外仓虚拟仓马来西亚:https://www.goluckyvip.com/tag/92615.html
马来西亚海外仓库:https://www.goluckyvip.com/tag/92616.html
大同旅游攻略一日游 山西大同一日游旅游景点有哪些:https://www.vstour.cn/a/408251.html
如何从帽儿山到哈尔滨火车站(详细交通路线及注意事项):https://www.vstour.cn/a/408252.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流