在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的时候,由于没有重定向页面,提示一句话

 

posted @ 2016-12-14 22:15  蝼蚁尚不自知  阅读(588)  评论(0编辑  收藏  举报