Java 怎么从servlet filterconfig获取布尔初始参数

2019年8月16日21:32:16Java 怎么从servlet filterconfig获取布尔初始参数已关闭评论 180 709字阅读2分21秒

1.简介

Java 怎么从servlet filterconfig获取布尔初始参数?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import javax.servlet.FilterConfig;
import javax.servlet.ServletException;

public class Main{
    
    public static boolean getBooleanInitParameter(
            FilterConfig theFilterConfig, String theInitParameterName,
            boolean isMandatory) throws ServletException {
        String returnedValueAsString = theFilterConfig
                .getInitParameter(theInitParameterName);
        if (isMandatory && (returnedValueAsString == null)) {
            throw new ServletException(theInitParameterName
                    + " parameter must be declared for "
                    + theFilterConfig.getFilterName() + " in web.xml");
        }
        boolean returnedValue = false;
        if (returnedValueAsString != null) {
            returnedValue = new Boolean(returnedValueAsString)
                    .booleanValue();
        }
        return returnedValue;
    }
}

 
编程十万个怎么办