zoukankan      html  css  js  c++  java
  • 在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的时候,由于没有重定向页面,提示一句话

  • 相关阅读:
    pku2351 Colored Sticks
    JSOI2010 满汉全席
    享元模式
    适配器模式
    合成模式
    原型模式
    创建型设计模式
    建造者模式
    装饰模式
    单例模式
  • 原文地址:https://www.cnblogs.com/xlh91118/p/6181318.html
Copyright © 2011-2022 走看看