我对ServletConfig接口的实现一直比较迷茫,想通过了解tomcat是如何对它做出实现来进一步认识ServletConfig.
[color=darkred][b]在构建一个servlet的时候需要容器提供一个ServletConfig对象,这个servletConfig对象的代码是如何实现的呢?主要就是servletConfig中的几个方法的实现代码!如果有地方可以查看源码,那是最好不过了![/b][/color]
查看servlet API相关信息如下:
javax.servlet Interface ServletConfig 有如下方法:
[color=blue][b]String getInitParameter(String name)[/b][/color]
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
[color=blue][b]Enumeration getInitParameterNames() [/b][/color]
Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.
[color=blue][b]ServletContext getServletContext() [/b][/color]
Returns a reference to the ServletContext in which the caller is executing.
[color=blue][b]String getServletName() [/b][/color]
Returns the name of this servlet instance
javax.servlet Interface Servlet 有如下几个方法:
[color=blue][b] void destroy()[/b][/color]
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
[color=blue][b]ServletConfig getServletConfig() [/b][/color]
Returns a ServletConfig object, which contains initialization and startup parameters for this servlet.
[color=blue][b] String getServletInfo() [/b][/color]
Returns information about the servlet, such as author, version, and copyright.
[color=blue][b] void init(ServletConfig config) [/b][/color]
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
[color=blue][b] void service(ServletRequest req, ServletResponse res) [/b][/color]
Called by the servlet container to allow the servlet to respond to a request.