⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionservlet.java

📁 java版源代码,里面包含很多源代码,大家可以看看.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      cl[0] = Class.forName("javax.servlet.http.HttpServletRequest");
      cl[1] = Class.forName("javax.servlet.http.HttpServletResponse");
      cl[2] = Class.forName("com.trulytech.mantis.system.SQLParser");

      Object[] obj = new Object[3];
      obj[0] = request;
      obj[1] = response;
      obj[2] = Parser;

      Method method = this.getClass().getMethod(MethodName, cl);
      return (String) method.invoke(this, obj);
    }

    catch (NoSuchMethodException e) {

      logWriter.Error(e.toString() + " (" + this.getClass().getName() + ")");
      return alert(request, response, Parser);

    }

  }

  /**
   * 执行doInit操作
   * @throws ServletException
   */
  protected void PerformInit() throws ServletException {

  }

  /**
   * 执行doDestory操作
   * @throws Exception
   */
  protected void PerformDestory() {

  }

//Clean up resources
  public final void destroy() {
    Properties.destory();
    PerformDestory();
    System.gc();
  }

  /**
   * 显示错误页
   * @param request 请求
   * @param response response
   * @param e 错误
   */
  protected void handleExp(HttpServletRequest request,
                           HttpServletResponse response, Exception e) {
    //如果是response错误
    if (Properties.isResponseErr) {
      try {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                           e.getMessage());
      }
      catch (Exception ex) {
        logWriter.Error(ex.toString() + " (" + this.getClass().getName() + ")");
      }
    }
    //如果是自定义错误
    else {
      try {
        request.setAttribute("Error", e);
        Dispatch(request, response, Properties.ErrPageURL);

      }
      catch (Exception ex) {
        logWriter.Error(ex.toString() + " (" + this.getClass().getName() + ")");
      }
    }
  }

  /**
   * 显示时间超时
   * @param request 请求
   * @param response response
   * @param e 超时错误
   */
  protected void handleTimeout(HttpServletRequest request,
                               HttpServletResponse response, TimeoutException e) {
    //如果是response错误
    if (Properties.isResponseTimeout) {
      try {
        response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT);
      }
      catch (Exception ex) {
        logWriter.Error(ex.toString() + " (" + this.getClass().getName() + ")");
      }

    }
    //如果是自定义错误
    else {
      try {
        //设置出现Timeout的URL地址
        request.getSession(true).setAttribute("URL",
                                              request.getRequestURI() + "?" +
                                              request.getQueryString());
        request.setAttribute("Error", e);
        Dispatch(request, response, Properties.TimeoutURL);

      }
      catch (Exception ex) {
        logWriter.Error(ex.toString() + " (" + this.getClass().getName() + ")");
      }
    }
  }

  /**
   * 获得输入参数,处理非空字段
   * @param request 请求
   * @param Name 名称
   * @return String
   */
  protected String getParameter(HttpServletRequest request, String Name) {
    String tmpStr = request.getParameter(Name);
    if (tmpStr == null)
      tmpStr = "";
    if (Properties.isConvert)
      return Properties.ConvertCharset(tmpStr);
    else
      return tmpStr;
  }

  /**
   * 获得多个输入参数,处理非空字段
   * @param request 请求
   * @param Name 名称
   * @return ArrayList
   */
  protected ArrayList getParameters(HttpServletRequest request, String Name) {
    ArrayList list = new ArrayList();
    String tmpStr[] = request.getParameterValues(Name);
    if (tmpStr != null) {
      for (int i = 0; i < tmpStr.length; i++) {
        if (tmpStr[i] == null)
          tmpStr[i] = "";
        if (Properties.isConvert)
          list.add(Properties.ConvertCharset(tmpStr[i]));
        else
          list.add(tmpStr[i]);
      }
    }
    return list;
  }

  /**
   * 显示非法提示
   * @return String
   * @param request request
   * @param response response
   * @param Parser Parser
   * @throws java.lang.Exception Exception
   */
  protected String alert(HttpServletRequest request,
                         HttpServletResponse response, SQLParser Parser) throws
      Exception {
    //如果是reponse信息
    if (com.trulytech.mantis.system.Properties.isResponseAlert) {
      response.sendError(HttpServletResponse.SC_FORBIDDEN);
      return "";
    }
    //如果是自定义信息
    else {
      String info = null;
      if (com.trulytech.mantis.system.Properties.isInternational)
        info = InternationalManager.getResource(request,
                                                com.trulytech.mantis.system.
                                                Properties.KeyBadCommand);
      else
        info = "操作非法!";
      logWriter.Error("操作非法!(" + this.getClass().getName() +
                      "-" +
                      getParameter(request,
                                   com.trulytech.mantis.system.Properties.
                                   Action_Tag) +
                      ")");
      request.setAttribute("Info", info);
      request.setAttribute("Action", "javascript:history.back();");
      return com.trulytech.mantis.system.Properties.AlertURL;
    }
  }

  /**
   * 身份校验,判断用户是否有相关权限
   * @param request request
   * @param response response
   * @param Parser SQL解分器
   * @return 是否具有权限 Permission.ERROR-页面超时 Permission.DENY-无权限 Permission.ALLOW-有权限
   * @throws java.lang.Exception
   */
  protected int HasPermission(HttpServletRequest request,
                              HttpServletResponse response, SQLParser Parser) throws
      Exception {

    HttpSession session = request.getSession(false);
    if (session == null)
      return Permission.ERROR;
//取用户ID
    else {
      String ID = (String) session.getAttribute(com.trulytech.mantis.system.
                                                Properties.Session_UserID);

      if (ID == null)
        return Permission.ERROR;

//取权限对象
      else {
        Permission perm = (Permission) session.getAttribute(com.trulytech.
            mantis.system.Properties.Session_Permission);
        if (perm == null) {
          if (Properties.HasPermission)
            return Permission.ERROR;
          else
            return Permission.ALLOW;
        }
//判断权限
        else {
          String ServletName = this.getClass().getName();

          int myPos = ServletName.lastIndexOf(".") + 1;
          String className = ServletName.substring(myPos,
              ServletName.length());

          String Action = getParameter(request,
                                       com.trulytech.mantis.system.
                                       Properties.
                                       Action_Tag);
          return perm.HasPermission(ID, className, Action, Parser);
        }
      }
    }

  }

  /**
   * 显示无权限信息
   * @param request request
   * @param response response
   * @param Parser Parser
   * @throws java.lang.Exception
   */
  protected void showinvalidate(HttpServletRequest request,
                                HttpServletResponse response, SQLParser Parser) throws
      Exception {
    //如果是reponse信息
    if (com.trulytech.mantis.system.Properties.isResponseAlert) {
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);

    }
    //如果是自定义错误
    else {

      String info = null;
      if (com.trulytech.mantis.system.Properties.isInternational)
        info = InternationalManager.getResource(request,
                                                com.trulytech.mantis.system.
                                                Properties.KeyPermissionDeny);
      else
        info = "该用户尚无此权限!";
      logWriter.Info("该用户尚无此权限!(" + this.getClass().getName() +
                     "-" +
                     getParameter(request,
                                  com.trulytech.mantis.system.Properties.
                                  Action_Tag) +
                     ")");
      request.setAttribute("Info", info);
      request.setAttribute("Action", "javascript:history.back();");
      Dispatch(request, response,
               com.trulytech.mantis.system.Properties.AlertURL);
    }
  }

  /**
   * 显示提示信息
   * @param request HttpServletRequest
   * @param Info String 提示信息
   * @param CallBackURL String 回调地址
   * @return String 调用URL
   * @throws Exception
   */
  protected String ShowMessage(HttpServletRequest request,
                               String Info, String CallBackURL) throws
      Exception {
    request.setAttribute("Info", Info);
    request.setAttribute("Action", CallBackURL);
    return com.trulytech.mantis.system.Properties.AlertURL;

  }

  /**
   * 页面转发
   * @param request HttpServletRequest
   * @param response HttpServletResponse
   * @param URL String
   * @throws Exception
   */
  protected void Dispatch(HttpServletRequest request,
                          HttpServletResponse response, String URL) throws
      Exception {
    if (URL != null) {
      if (URL.length() > 0) {
        if (URL.charAt(0) != '/')
          URL = "/" + URL;
        getServletContext().getRequestDispatcher(URL).forward(
            request,
            response);
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -