zoukankan      html  css  js  c++  java
  • java的过滤器对session进行检查

     1 private void sendErrorToBrowser(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
     2     //请求类型
     3     String requestType = request.getHeader("X-Requested-With");
     4     
     5     //ajax请求
     6     if("XMLHttpRequest".equals(requestType)){
     7         response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
     8     }else{
     9         String path = request.getContextPath();
    10         String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    11         response.sendRedirect(basePath+"login.jsp");
    12     }
    13 }

    如果是页面请求:

    跳转到未登陆处理页面参考:http://www.cnblogs.com/yangzhilong/archive/2013/01/28/2880135.html

    如果是ajax请求:

    $.ajax({
        type : "POST",
        url : url,
        data : parma,
        dataType : "json",
        success : function(jsonObj) {
            
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            if(401==XMLHttpRequest.status){
                alert("请登陆后再操作!");
                window.top.location.replace(basepath + "login.jsp");
            }else{
                alert("计算失败,服务器发生错误,请联系系统管理员!");
           } 
        },
        beforeSend: function(){
            
        }
    });
  • 相关阅读:
    CF991D Bishwock
    CF1010D Mars rover
    NOIP 2011 计算系数
    SDOI 2008 仪仗队
    浅谈欧拉函数
    CF1249F Maximum Weight Subset
    NOIP 2011 铺地毯
    CF707D Persistent Bookcase
    C++ STL bitset 容器详解
    CF798D Mike and distribution
  • 原文地址:https://www.cnblogs.com/yangzhilong/p/4059996.html
Copyright © 2011-2022 走看看