知识库--ServletConfig Object(54)
来源:互联网 发布:足球基本技术动作知乎 编辑:程序博客网 时间:2024/04/29 12:17
The loadServlet method of the StandardWrapper class calls the sender’s init method after the servlet is loaded. The init method is passed an instance of javax.servlet.ServletConfig. You may be wondering how the StandardWrapper object obtains the ServletConfig object.
//实现了ServletConfig接口
Look no further than the StandardWrapper class itself. This class implements the javax.servlet.ServletConfig interface, in addition to the Wrapper interface.
getServletContext, getServletName, getInitParameter, and getInitParameterNames;
Note The StandardWrapper class does not pass itself to the servlet’s init method, however, it wraps itself in a StandardWrapperFacade instance to hide most of its public method from a servlet programmer.
1 The signature of this method is as follows:
public ServletContext getServletContext(); //调用上级容器的相同方法签名
A StandardWrapper instance must be a child container of a StandardContext. This is to say, a StandardWrapper’s parent is a StandardContext. From the StandardContext object, you can obtain a ServletContext object calling its getServletContext method in the StandardWrapper class:
public ServletContext getServletContext(){ if(parent == null){ return null; }else if(!(parent instanceof Context)){ return null; }else{ return ((Context)parent).getServletContext(); } }
2 getServletName method
public String getServletName();
实际上还是调用了父类 ContainerBase的 getName()方法
public String getName(){ return name; }
3 getInitParameter method
public String getInitParameter(String name)
In StandardWrapper, the initialization parameters are stored in a HashMap named parameters.
public HashMap parameters = new HashMap();
//填充参数
You populate parameters by calling the StandardWrapper class’s addInitParameter method, passing the name and the value of the parameter.
public void addInitParameter(String name, String value){ synchronized(parameters){ parameters.put(name,value); } fireContainerEvent("addInitParameter",name); }
The implementation of getInitParameter in StandardWrapper:
public String getInitParameter(String name){ return (findInitParameter(name)); } public String findInitParameter(String name){ synchronized(parameters){ return ((String)parameters.get(name)); } }
4 getInitParameterNames
public Enumeration getInitParameterNames(){ synchronized(parameters){ return (new Enumerator(parameters.keyset())); } }
“Parent and Children
A wrapper represents a container for each individual servlet. As such, a wrapper cannot have a child, and its addChild method should not be called. If you did, you would get a java.lang.IllegalStateException. Here is the implementation of the addChild method in the StandardWrapper class:
public void addChild(Container child){ throw new IllegalStateException("StandardWrapper.notChild");}
A wrapper’s parent can only be an implementation of Context. Its setParent method throws a java.lang.IllegalArgumentException if you pass a non-Context container to it.
public void setParent(Container container){ if((container != null) && !(container instanceof Context)){ throw new IllegalArgumentException("standardWrapper.notContext"); } super.setParent(container); }
- 知识库--ServletConfig Object(54)
- ServletConfig
- servletConfig
- ServletConfig
- servletconfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig
- servletConfig
- servletconfig
- ServletConfig
- ServletConfig
- ServletConfig
- 知识库--StandardWrapperFacade(54)
- 知识库--StandardWrapperValve(54)
- java中的反射机制
- ns-3 Tracer 原理以及应用/ndnSIM Tracer原理以及应用
- 树梅派应用14:树莓派 Raspberry Pi 设置无线上网
- Hadoop
- Ubuntu 16安装QQ
- 知识库--ServletConfig Object(54)
- Spring 发送邮件
- 一些代码感受
- Virginia(维吉尼亚)无密钥解密
- Java多态的实现:类型信息(RTTI)
- offsetX,clientX,screenX,pageX的比较小结
- 初识之C#
- INSERT 语句与 FOREIGN KEY 约束"XXX"冲突。
- 树梅派应用15:树莓派+motion安装摄像头实现远程监控