• 在spring拦截器中response输出html标签到页面


      @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
                throws Exception {
            String tokenValue = request.getParameter(FORM_TOKEN);
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            Method method = handlerMethod.getMethod();
            boolean isDuplicateSubmitType = method.isAnnotationPresent(DuplicateSubmit.class);
            if (isDuplicateSubmitType) {
                long result = cacheManager.increment(tokenValue);
                cacheManager.setString(tokenValue, "1", 5000);
                // 判断返回值是否大于1,如果是则重复提交
                if (result > 1) {
                    LOGGER.error("【" + request.getRequestURL() + "==>" + method.getName() + "】" + "的方法表单重复提交");
                    response.setCharacterEncoding("utf-8");
                    response.setContentType("text/html");
                    PrintWriter out = response.getWriter();
                    out.write("重复提交  <a href= 'javascript:history.go(-1)'>点击返回</a>");
                    out.close();
                    return false;
                }
            }
            return true;
        }

    背景:在spring的连接器中,当preHandle返回false的时候,由于没有重定向页面,提示一句话

  • 相关阅读:
    windows下安装和设置Git客户端
    普通年金终值和现值计算(白话版)
    Git Http Server
    Python容器数据类型——collections
    模拟二进制实现减法
    自己写的线程池
    买书问题
    电梯调度算法
    Python文本常量和模板——string
    shell变量设置与显示
  • 原文地址:https://www.cnblogs.com/xlh91118/p/6181318.html
Copyright © 2020-2023  润新知