Servlet下
servlet容器启动过程
Web应用的初始化工作
创建Servlet实例
在Servlet的解析工作中,Servlet被包装成StandarWrapper添加在Context容器中。
servlet 体系结构
servlet interface:
package javax.servlet; import java.io.IOException; public interface Servlet { void init(ServletConfig var1) throws ServletException; ServletConfig getServletConfig(); void service(ServletRequest var1, ServletResponse var2) throws ServletException, IOException; String getServletInfo(); void destroy(); }
servletConfig interface:
package javax.servlet; import java.util.Enumeration; public interface ServletConfig { String getServletName(); ServletContext getServletContext(); String getInitParameter(String var1); Enumeration getInitParameterNames(); }
servletContext interface:
package javax.servlet; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; import java.util.Set; public interface ServletContext { String getContextPath(); ServletContext getContext(String var1); int getMajorVersion(); int getMinorVersion(); String getMimeType(String var1); Set getResourcePaths(String var1); URL getResource(String var1) throws MalformedURLException; InputStream getResourceAsStream(String var1); RequestDispatcher getRequestDispatcher(String var1); RequestDispatcher getNamedDispatcher(String var1); /** @deprecated */ Servlet getServlet(String var1) throws ServletException; /** @deprecated */ Enumeration getServlets(); /** @deprecated */ Enumeration getServletNames(); void log(String var1); /** @deprecated */ void log(Exception var1, String var2); void log(String var1, Throwable var2); String getRealPath(String var1); String getServerInfo(); String getInitParameter(String var1); Enumeration getInitParameterNames(); Object getAttribute(String var1); Enumeration getAttributeNames(); void setAttribute(String var1, Object var2); void removeAttribute(String var1); String getServletContextName(); }
servletRequest interface:
package javax.servlet; import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Locale; import java.util.Map; public interface ServletRequest { Object getAttribute(String var1); Enumeration getAttributeNames(); String getCharacterEncoding(); void setCharacterEncoding(String var1) throws UnsupportedEncodingException; int getContentLength(); String getContentType(); ServletInputStream getInputStream() throws IOException; String getParameter(String var1); Enumeration getParameterNames(); String[] getParameterValues(String var1); Map getParameterMap(); String getProtocol(); String getScheme(); String getServerName(); int getServerPort(); BufferedReader getReader() throws IOException; String getRemoteAddr(); String getRemoteHost(); void setAttribute(String var1, Object var2); void removeAttribute(String var1); Locale getLocale(); Enumeration getLocales(); boolean isSecure(); RequestDispatcher getRequestDispatcher(String var1); /** @deprecated */ String getRealPath(String var1); int getRemotePort(); String getLocalName(); String getLocalAddr(); int getLocalPort(); }
servletResponse interface:
package javax.servlet; import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Locale; import java.util.Map; public interface ServletRequest { Object getAttribute(String var1); Enumeration getAttributeNames(); String getCharacterEncoding(); void setCharacterEncoding(String var1) throws UnsupportedEncodingException; int getContentLength(); String getContentType(); ServletInputStream getInputStream() throws IOException; String getParameter(String var1); Enumeration getParameterNames(); String[] getParameterValues(String var1); Map getParameterMap(); String getProtocol(); String getScheme(); String getServerName(); int getServerPort(); BufferedReader getReader() throws IOException; String getRemoteAddr(); String getRemoteHost(); void setAttribute(String var1, Object var2); void removeAttribute(String var1); Locale getLocale(); Enumeration getLocales(); boolean isSecure(); RequestDispatcher getRequestDispatcher(String var1); /** @deprecated */ String getRealPath(String var1); int getRemotePort(); String getLocalName(); String getLocalAddr(); int getLocalPort(); }
ServletConfig在Servlet init时由容器传过来。
Servlet如何工作
服务器如何根据URL到达正确地Servlet容器中的。
Servlet中的Listener
Filter如何工作
filter interface:
package javax.servlet; import java.io.IOException; public interface Filter { void init(FilterConfig var1) throws ServletException; void doFilter(ServletRequest var1, ServletResponse var2, FilterChain var3) throws IOException, ServletException; void destroy(); }
filterConfig interface:
package javax.servlet; import java.util.Enumeration; public interface FilterConfig { String getFilterName(); ServletContext getServletContext(); String getInitParameter(String var1); Enumeration<String> getInitParameterNames(); }
filterChain interface:
package javax.servlet; import java.io.IOException; public interface FilterChain { void doFilter(ServletRequest var1, ServletResponse var2) throws IOException, ServletException; }