// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: HttpServlet.java
package javax.servlet.http;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.ResourceBundle;
import javax.servlet.*;
// Referenced classes of package javax.servlet.http:
// NoBodyResponse, HttpServletRequest, HttpServletResponse
public abstract class HttpServlet extends GenericServlet
implements Serializable
{
private static final String METHOD_DELETE = "DELETE";
private static final String METHOD_HEAD = "HEAD";
private static final String METHOD_GET = "GET";
private static final String METHOD_OPTIONS = "OPTIONS";
private static final String METHOD_POST = "POST";
private static final String METHOD_PUT = "PUT";
private static final String METHOD_TRACE = "TRACE";
private static final String HEADER_IFMODSINCE = "If-Modified-Since";
private static final String HEADER_LASTMOD = "Last-Modified";
private static final String LSTRING_FILE = "javax.servlet.http.LocalStrings";
private static ResourceBundle lStrings = ResourceBundle.getBundle("javax.servlet.http.LocalStrings");
public HttpServlet()
{
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_get_not_supported");
if (protocol.endsWith("1.1"))
resp.sendError(405, msg);
else
resp.sendError(400, msg);
}
protected long getLastModified(HttpServletRequest req)
{
return -1L;
}
protected void doHead(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
NoBodyResponse response = new NoBodyResponse(resp);
doGet(req, response);
response.setContentLength();
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_post_not_supported");
if (protocol.endsWith("1.1"))
resp.sendError(405, msg);
else
resp.sendError(400, msg);
}
protected void doPut(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_put_not_supported");
if (protocol.endsWith("1.1"))
resp.sendError(405, msg);
else
resp.sendError(400, msg);
}
protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_delete_not_supported");
if (protocol.endsWith("1.1"))
resp.sendError(405, msg);
else
resp.sendError(400, msg);
}
private static Method[] getAllDeclaredMethods(Class c)
{
if (c.equals(javax/servlet/http/HttpServlet))
return null;
Method parentMethods[] = getAllDeclaredMethods(c.getSuperclass());
Method thisMethods[] = c.getDeclaredMethods();
if (parentMethods != null && parentMethods.length > 0)
{
Method allMethods[] = new Method[parentMethods.length + thisMethods.length];
System.arraycopy(parentMethods, 0, allMethods, 0, parentMethods.length);
System.arraycopy(thisMethods, 0, allMethods, parentMethods.length, thisMethods.length);
thisMethods = allMethods;
}
return thisMethods;
}
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
Method methods[] = getAllDeclaredMethods(getClass());
boolean ALLOW_GET = false;
boolean ALLOW_HEAD = false;
boolean ALLOW_POST = false;
boolean ALLOW_PUT = false;
boolean ALLOW_DELETE = false;
boolean ALLOW_TRACE = true;
boolean ALLOW_OPTIONS = true;
for (int i = 0; i < methods.length; i++)
{
Method m = methods[i];
if (m.getName().equals("doGet"))
{
ALLOW_GET = true;
ALLOW_HEAD = true;
}
if (m.getName().equals("doPost"))
ALLOW_POST = true;
if (m.getName().equals("doPut"))
ALLOW_PUT = true;
if (m.getName().equals("doDelete"))
ALLOW_DELETE = true;
}
String allow = null;
if (ALLOW_GET && allow == null)
allow = "GET";
if (ALLOW_HEAD)
if (allow == null)
allow = "HEAD";
else
allow = (new StringBuilder()).append(allow).append(", HEAD").toString();
if (ALLOW_POST)
if (allow == null)
allow = "POST";
else
allow = (new StringBuilder()).append(allow).append(", POST").toString();
if (ALLOW_PUT)
if (allow == null)
allow = "PUT";
else
allow = (new StringBuilder()).append(allow).append(", PUT").toString();
if (ALLOW_DELETE)
if (allow == null)
allow = "DELETE";
else
allow = (new StringBuilder()).append(allow).append(", DELETE").toString();
if (ALLOW_TRACE)
if (allow == null)
allow = "TRACE";
else
allow = (new StringBuilder()).append(allow).append(", TRACE").toString();
if (ALLOW_OPTIONS)
if (allow == null)
allow = "OPTIONS";
else
allow = (new StringBuilder()).append(allow).append(", OPTIONS").toString();
resp.setHeader("Allow", allow);
}
protected void doTrace(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String CRLF = "\r\n";
String responseString = (new StringBuilder()).append("TRACE ").append(req.getRequestURI()).append(" ").append(req.getProtocol()).toString();
for (Enumeration reqHeaderEnum = req.getHeaderNames(); reqHeaderEnum.hasMoreElements();)
{
String headerName = (String)reqHeaderEnum.nextElement();
responseString = (new StringBuilder()).append(responseString).append(CRLF).append(headerName).append(": ").append(req.getHeader(headerName)).toString();
}
responseString = (new StringBuilder()).append(responseString).append(CRLF).toString();
int responseLength = responseString.length();
resp.setContentType("message/http");
resp.setContentLength(responseLength);
ServletOutputStream out = resp.getOutputStream();
out.print(responseString);
out.close();
}
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String method = req.getMethod();
if (method.equals("GET"))
{
long lastModified = getLastModified(req);
if (lastModified == -1L)
{
doGet(req, resp);
} else
{
long ifModifiedSince = req.getDateHeader("If-Modified-Since");
if (ifModifiedSince < (lastModified / 1000L) * 1000L)
{
maybeSetLastModified(resp, lastModified);
doGet(req, resp);
} else
{
resp.setStatus(304);
}
}
} else
if (method.equals("HEAD"))
{
long lastModified = getLastModified(req);
maybeSetLastModified(resp, lastModified);
doHead(req, resp);
} else
if (method.equals("POST"))
doPost(req, resp);
else
if (method.equals("PUT"))
doPut(req, resp);
else
if (method.equals("DELETE"))
doDelete(req, resp);
else
if (method.equals("OPTIONS"))
doOptions(req, resp);
else
if (method.equals("TRACE"))
{
doTrace(req, resp);
} else
{
String errMsg = lStrings.getString("http.method_not_implemented");
Object errArgs[] = new Object[1];
errArgs[0] = method;
errMsg = MessageFormat.format(errMsg, errArgs);
resp.sendError(501, errMsg);
}
}
private void maybeSetLastModified(HttpServletResponse resp, long lastModified)
{
if (resp.containsHeader("Last-Modified"))
return;
if (lastModified >= 0L)
resp.setDateHeader("Last-Modified", lastModified);
}
public void service(ServletRequest req, Servlet
没有合适的资源?快使用搜索试试~ 我知道了~
HttpServletRequest源码 HttpServletResponse源码
共113个文件
java:59个
class:42个
xsd:6个
4星 · 超过85%的资源 需积分: 50 501 下载量 147 浏览量
2011-04-06
19:05:56
上传
评论 3
收藏 131KB ZIP 举报
温馨提示
java HttpServletRequest HttpServletResponse 源码 request response
资源推荐
资源详情
资源评论
收起资源包目录
HttpServletRequest源码 HttpServletResponse源码 (113个子文件)
HttpServlet.class 8KB
NoBodyResponse.class 5KB
HttpUtils.class 4KB
ServletRequestWrapper.class 4KB
Cookie.class 3KB
HttpServletRequestWrapper.class 3KB
ServletOutputStream.class 3KB
HttpServletResponseWrapper.class 3KB
HttpServletResponse.class 3KB
ServletResponseWrapper.class 3KB
GenericServlet.class 2KB
ServletContext.class 1KB
HttpServletRequest.class 1KB
ServletRequest.class 1KB
UnavailableException.class 1KB
NoBodyOutputStream.class 1KB
HttpSessionBindingEvent.class 1KB
ServletRequestAttributeEvent.class 944B
HttpSession.class 872B
ServletException.class 863B
ServletRequestEvent.class 846B
ServletContextAttributeEvent.class 833B
ServletResponse.class 733B
ServletInputStream.class 637B
HttpSessionEvent.class 626B
ServletContextEvent.class 624B
Servlet.class 473B
Filter.class 389B
ServletConfig.class 360B
FilterConfig.class 357B
RequestDispatcher.class 330B
ServletRequestAttributeListener.class 318B
ServletContextAttributeListener.class 318B
HttpSessionAttributeListener.class 317B
HttpSessionActivationListener.class 292B
FilterChain.class 289B
HttpSessionContext.class 288B
HttpSessionBindingListener.class 277B
ServletContextListener.class 267B
ServletRequestListener.class 267B
HttpSessionListener.class 264B
SingleThreadModel.class 148B
web-app_2_3.dtd 34KB
web-app_2_2.dtd 16KB
XMLSchema.dtd 16KB
datatypes.dtd 7KB
HttpServlet.java 8KB
HttpServlet.java 8KB
NoBodyResponse.java 4KB
NoBodyResponse.java 4KB
HttpUtils.java 4KB
HttpUtils.java 4KB
HttpServletResponse.java 4KB
HttpServletResponse.java 4KB
ServletRequestWrapper.java 3KB
HttpServletRequestWrapper.java 3KB
HttpServletRequestWrapper.java 3KB
Cookie.java 3KB
Cookie.java 3KB
HttpServletResponseWrapper.java 3KB
HttpServletResponseWrapper.java 3KB
ServletOutputStream.java 2KB
ServletResponseWrapper.java 2KB
ServletContext.java 2KB
HttpServletRequest.java 2KB
HttpServletRequest.java 2KB
ServletRequest.java 2KB
GenericServlet.java 2KB
HttpSession.java 2KB
HttpSession.java 2KB
UnavailableException.java 1KB
ServletResponse.java 1KB
NoBodyOutputStream.java 1KB
NoBodyOutputStream.java 1KB
HttpSessionBindingEvent.java 929B
HttpSessionBindingEvent.java 929B
ServletRequestAttributeEvent.java 794B
Servlet.java 790B
ServletRequestAttributeListener.java 775B
ServletContextAttributeListener.java 775B
ServletRequestEvent.java 769B
ServletContextAttributeEvent.java 753B
HttpSessionAttributeListener.java 744B
HttpSessionAttributeListener.java 744B
Filter.java 732B
ServletInputStream.java 729B
RequestDispatcher.java 711B
HttpSessionContext.java 700B
HttpSessionContext.java 700B
ServletException.java 667B
HttpSessionBindingListener.java 639B
HttpSessionBindingListener.java 639B
HttpSessionActivationListener.java 626B
HttpSessionActivationListener.java 626B
ServletContextListener.java 613B
ServletRequestListener.java 613B
ServletConfig.java 607B
FilterConfig.java 604B
ServletContextEvent.java 601B
HttpSessionListener.java 598B
共 113 条
- 1
- 2
shiningj
- 粉丝: 8
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页