标签:des style blog class code java
最近看tomcat源码,这类接口多的有点眩,整理出来看一下。(基于tomcat4)
javax.servlet.ServletRequset接口,和org.apache.catalina.Request接口,有什么联系?
其实就是对Request不同层面上的定义。
package javax.servlet; import java.io.IOException; public abstract interface Servlet { public abstract void init(ServletConfig paramServletConfig) throws ServletException; public abstract ServletConfig getServletConfig(); public abstract void service(ServletRequest paramServletRequest, ServletResponse paramServletResponse) throws ServletException, IOException; public abstract String getServletInfo(); public abstract void destroy(); }
这些方法应该非常熟悉了。
package javax.servlet.http; public abstract class HttpServlet extends GenericServlet implements Serializable { ... }
丰富了servlet接口,对应http协议,添加了doGet, doPut, doPost等方法。
package javax.servlet; public abstract interface ServletRequest { public abstract Object getAttribute(String paramString); public abstract Enumeration getAttributeNames(); public abstract String getCharacterEncoding(); public abstract void setCharacterEncoding(String paramString) throws UnsupportedEncodingException; public abstract int getContentLength(); public abstract String getContentType(); public abstract ServletInputStream getInputStream() throws IOException; public abstract String getParameter(String paramString); public abstract Enumeration getParameterNames(); public abstract String[] getParameterValues(String paramString); public abstract Map getParameterMap(); public abstract String getProtocol(); public abstract String getScheme(); public abstract String getServerName(); public abstract int getServerPort(); public abstract BufferedReader getReader() throws IOException; public abstract String getRemoteAddr(); public abstract String getRemoteHost(); public abstract void setAttribute(String paramString, Object paramObject); public abstract void removeAttribute(String paramString); public abstract Locale getLocale(); public abstract Enumeration getLocales(); public abstract boolean isSecure(); public abstract RequestDispatcher getRequestDispatcher(String paramString); /** @deprecated */ public abstract String getRealPath(String paramString); }
public abstract interface HttpServletRequest extends ServletRequest {...}
添加了http协议部分,比如session,cookie等。
package org.apache.catalina; public interface Request { public String getAuthorization(); public void setAuthorization(String authorization); public Connector getConnector(); public void setConnector(Connector connector); public Context getContext(); public void setContext(Context context); public String getInfo(); public ServletRequest getRequest(); public Response getResponse(); public void setResponse(Response response); public Socket getSocket(); public void setSocket(Socket socket); public InputStream getStream(); public void setStream(InputStream stream); public Wrapper getWrapper(); public void setWrapper(Wrapper wrapper); public ServletInputStream createInputStream() throws IOException; public void finishRequest() throws IOException; public Object getNote(String name); public Iterator getNoteNames(); public void recycle(); public void removeNote(String name); public void setContentLength(int length); public void setContentType(String type); public void setNote(String name, Object value); public void setProtocol(String protocol); public void setRemoteAddr(String remote); public void setScheme(String scheme); public void setSecure(boolean secure); public void setServerName(String name); public void setServerPort(int port); }
public interface HttpRequest extends Request {...}
增加了对http协议头处理部分,比如url,参数,cookies等。
虽然已经弃用了,但可以作为一个参考,实现了jdk和catalina定义的Request
public class HttpRequestBase extends RequestBase implements HttpRequest, HttpServletRequest {...}
tomcat中,对于jdk中的servlet和ServletRequest肯定要实现的。而tomcat作为容器应用,会有很多自身的需求,所以自己定义了一套接口,跟jdk中不同层面。并且提供两套接口的类,让web开发者使用。
Request、Servlet及其子接口,布布扣,bubuko.com
标签:des style blog class code java
原文地址:http://www.cnblogs.com/549294286/p/3704760.html