// Decompiled by DJ v3.8.8.85 Copyright 2005 Atanas Neshkov Date: 2007-7-29 14:25:30
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// 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
{
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 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);
el
没有合适的资源?快使用搜索试试~ 我知道了~
java servlet源代码
共62个文件
java:42个
xsd:9个
properties:7个
5星 · 超过95%的资源 需积分: 10 802 下载量 145 浏览量
2009-03-29
19:01:42
上传
评论
收藏 93KB RAR 举报
温馨提示
Servlet是一种独立于平台和协议的服务器端的Java应用程序,可以生成动态的Web页面。 它担当Web浏览器或其他HTTP客户程序发出请求,与HTTP服务器上的数据库或应用程序之间的中间层。 Servlet是位于Web 服务器内部的服务器端的Java应用程序,与传统的从命令行启动的Java应用程序不同,Servlet由Web服务器进行加载,该Web服务器必须包含支持Servlet的Java虚拟机。
资源推荐
资源详情
资源评论
收起资源包目录
servlet2.5-src.zip (62个子文件)
src
ServletContextListener.java 671B
Servlet.java 866B
ServletRequestListener.java 671B
ServletRequest.java 2KB
LocalStrings.properties 228B
ServletException.java 885B
FilterChain.java 620B
ServletRequestAttributeListener.java 836B
SingleThreadModel.java 409B
Filter.java 811B
UnavailableException.java 2KB
RequestDispatcher.java 778B
ServletOutputStream.java 3KB
ServletContext.java 2KB
ServletRequestWrapper.java 4KB
http
HttpSessionBindingEvent.java 1KB
HttpServletRequest.java 2KB
HttpServletResponseWrapper.java 3KB
HttpSessionAttributeListener.java 805B
HttpServlet.java 10KB
LocalStrings.properties 640B
HttpServletRequestWrapper.java 4KB
HttpSessionEvent.java 662B
NoBodyOutputStream.java 1KB
HttpSessionListener.java 656B
HttpSessionActivationListener.java 684B
HttpSessionBindingListener.java 697B
HttpServletResponse.java 4KB
LocalStrings_es.properties 763B
Cookie.java 3KB
HttpUtils.java 5KB
NoBodyResponse.java 5KB
HttpSessionContext.java 773B
LocalStrings_fr.properties 724B
LocalStrings_ja.properties 1KB
HttpSession.java 2KB
resources
javaee_5.xsd 62KB
j2ee_1_4.xsd 45KB
jsp_2_0.xsd 9KB
javaee_web_services_client_1_2.xsd 18KB
web-app_2_5.xsd 37KB
datatypes.dtd 6KB
XMLSchema.dtd 16KB
jsp_2_1.xsd 11KB
xml.xsd 3KB
web-app_2_2.dtd 18KB
web-app_2_3.dtd 32KB
web-app_2_4.xsd 35KB
j2ee_web_services_client_1_1.xsd 10KB
ServletResponseWrapper.java 3KB
ServletRequestEvent.java 872B
ServletResponse.java 1KB
ServletInputStream.java 880B
ServletContextAttributeEvent.java 865B
GenericServlet.java 3KB
ServletContextEvent.java 680B
ServletRequestAttributeEvent.java 906B
ServletConfig.java 668B
LocalStrings_fr.properties 163B
LocalStrings_ja.properties 198B
FilterConfig.java 665B
ServletContextAttributeListener.java 836B
共 62 条
- 1
LoveBaoBeiEr
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页