http 状态码的使用

http 状态码的使用

302

后台sendRedirect
什么情况会出现302呢?
服务器端跳转(response.sendRedirect)
比如我访问http://blog.hbjltv.com/convention/test/list
但是拦截器发现没有登录,就在服务器端跳转到登录页面(http://blog.hbjltv.com/convention/user/loginInput)

@Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object arg2) throws Exception {
        HttpSession session = request.getSession(true);

        if (!AuthenticateUtil.isLogined(session)) {
            String path = request.getRequestURI();//"/demo_channel_terminal/news/list"
            System.out.println("您无权访问:" + path);
            //用于登录成功之后回调
            session.setAttribute(LoginUtil.SESSION_KEY_LOGIN_RETURN_URL, path);
            System.out.println();
            String contextPath = request.getContextPath();
            response.setCharacterEncoding(SystemHWUtil.CHARSET_UTF);
            request.setCharacterEncoding("UTF-8");
            String message = null;
            if (ValueWidget.isNullOrEmpty(getErrorMessage())) {
                message = "您没有权限访问,请先登录.";
            } else {
                message = getErrorMessage();
            }
            log(request);
            response.sendRedirect(contextPath + getReturnUrl() + "?" + Constant2.RESPONSE_KEY_ERROR_MESSAGE + "=" + URLEncoder.encode(message, "UTF-8"));
            return false;
        }
        return true;
    }

401

表示没有权限
比如还没有登录,就进行修改,删除等操作

public static boolean redirectLogin(HttpServletResponse response, String callbackURL) throws IOException {
        response.setStatus(401);
        response.sendRedirect("http://i.chanjet.com/login?callback=" + callbackURL);
        return false;
    }

400

表示必须传的参数没有传递
比如,登录时没有传递用户名或者没有传递密码

405

请求方式不对
本来应该使用POST方式,结果使用GET方式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值