zoukankan      html  css  js  c++  java
  • Servlet--ServletException类,UnavailableException类

    • ServletException类
    定义
    public class ServletException extends Exception
    当 Servlet 遇到问题时抛出的一个异常。
    构造函数
    public ServletException();
    public ServletException(String message);
    public ServletException(String message, Throwable cause);
    public ServletException(Throwable cause);
    构造一个新的 ServletException,如果这个构造函数包括一个 Throwable 参数,这个Throwable 对象将被作为可能抛出这个异常的原因。
    方法
    1、getRootCause
    public Throwable getRootCause();
    如果配置了抛出这个异常的原因,这个方法将返回这个原因,否则返回一个空值。


    • UnavailableException类

    定义
    public class UnavailableException extends ServletException
    不论一个 Servlet 是永久地还是临时地无效,都会抛出这个异常。Servlet 会记录这个异常以及 Servlet 引擎所要采取的相应措施。临时的无效是指 Servlet 在某一时间由于一个临时的问题而不能处理请求。例如,在另一个不同的应用层的服务(可能是数据库)无法使用。这个问题可能会自行纠正或者需要采取其他的纠正措施。永久的无效是指除非管理员采取措施,这个 Servlet 将不能处理客户端的请求。例如,这个 Servlet 配置信息丢失或 Servlet 的状态被破坏。Servlet 引擎可以安全地处理包括永久无效在内的这两种异常,但是对临时无效的正常处理可以使得 Servlet 引擎更健壮。特别的,这时对 Servlet 的请求只是 被阻止(或者是被延期)一段时间,这显然要比在 service 自己重新启动前完全拒绝请求更为科学。
    构造函数
    public UnavailableException(Servlet servlet, String message);
    public UnavailableException(int seconds, Servlet servlet,String message);

    构造一个包含指定的描述信息的新的异常。如果这个构造函数有一个关于秒数的参数,这将给出 Servlet 发生临时无效后,能够重新处理请求的估计时间。如果不包含这个参数,这意味着这个 Servlet 永久无效。


    方法
    1、getServlet
    public Servlet getServlet();
    返回报告无效的 Servlet。这被 Servlet 引擎用来识别受到影响的 Servlet。
    2、getUnavailableSeconds
    public int getUnavailableSeconds();
    返回 Servlet 预期的无效时间,如果这个 Servlet 是永久无效,返回-1。
    3、isPermanent
    public boolean isPermanent();

    如果这个 Servlet 永久无效,返回布尔值 true,指示必须采取一些管理行动以使得这个Servlet 可用。

    package javax.servlet;
    
    public class UnavailableException extends ServletException
    {
      private Servlet servlet;
      private boolean permanent;
      private int seconds;
    
      /** @deprecated */
      public UnavailableException(Servlet servlet, String msg)
      {
        super(msg);
        this.servlet = servlet;
        this.permanent = true;
      }
    
      /** @deprecated */
      public UnavailableException(int seconds, Servlet servlet, String msg)
      {
        super(msg);
        this.servlet = servlet;
        if (seconds <= 0)
          this.seconds = -1;
        else
          this.seconds = seconds;
        this.permanent = false;
      }
    
      public UnavailableException(String msg)
      {
        super(msg);
    
        this.permanent = true;
      }
    
      public UnavailableException(String msg, int seconds)
      {
        super(msg);
    
        if (seconds <= 0)
          this.seconds = -1;
        else {
          this.seconds = seconds;
        }
        this.permanent = false;
      }
    
      public boolean isPermanent()
      {
        return this.permanent;
      }
    
      /** @deprecated */
      public Servlet getServlet()
      {
        return this.servlet;
      }
    
      public int getUnavailableSeconds()
      {
        return this.permanent ? -1 : this.seconds;
      }
    }


  • 相关阅读:
    Oracle 备份与恢复介绍
    Oracle 监听器
    ORA-01041: 内部错误,hostdef 扩展名不存在
    NIO读写文件并加锁
    ActiveMQ消息生产消费流程
    金额,有效值等保留小数位处理
    JVM
    Linux架构分布式集群之基础篇
    Vue.js 开发实践:实现精巧的无限加载与分页功能
    Mysql 查看连接数,状态
  • 原文地址:https://www.cnblogs.com/LinkinPark/p/5233021.html
Copyright © 2011-2022 走看看