阅读436 返回首页    go 阿里云 go 技术社区[云栖]


一种表单重复提交处理方法

表单重复提交处理:

1. 在生成表单时执行如下:


   session.setAttribute("forum_add", "forum_add");

2. 提交处理时作如下判断

        if (isRedo(request, "forum_add")) {
            //提示重复提交,作相关处理
        }


相关函数:

    /**
     * 判断是否为重复提交
     * 1,检查Session中是否含有指定名字的属性
     * 2,如果Session中没有该属性或者属性为空,证明已被处理过,判断为重复提交
     * 3,否则,证明是第一次处理,并将属性从Session中删除。
     * @param key String
     */
    private boolean isRedo(HttpServletRequest request, String key) {
        String value = (String) request.getSession().getAttribute(key);
        if (value == null) {
            return true;
        }
        else {
            request.getSession().removeAttribute(key);
            return false;
        }
    }

 

最后更新:2017-04-02 03:42:36

  上一篇:go 为struts2中自己实现webwork2中的AroundInterceptor拦截器
  下一篇:go 数据库连接DBSource.java类