Servlet 简介:
Servlet是sun公司提供的一门用于开发动态web资源的技术。
Sun公司在其API中提供了一个servlet接口,用户若想开发一个动态web资源(即开发一个Java程序向浏览器输出数据),需要完成以下两步:
1.编写一个Java类,实现servlet接口;
2.把开发好的Java类部署到web服务器中。
jsp就是servlet
javase、javaee,servlet不属于javase而属于javaee
servlet专门文档API
Tomcat可以运行servlet,lib里面有servlet的jar包
用记事本或UltraEdit编写java程序,用Java、javac编译运行
Servlet在线API:http://tomcat.apache.org/tomcat-5.5-doc/servletapi/
public interface Servlet
Defines methods that all servlets must implement.
A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol.
To implement this interface, you can write a generic servlet that extends javax.servlet.GenericServlet or an HTTP servlet that extends javax.servlet.http.HttpServlet.
This interface defines methods to initialize a servlet, to service requests, and to remove a servlet from the server. These are known as life-cycle methods and are called in the following sequence:
The servlet is constructed, then initialized with the init method.
Any calls from clients to the service method are handled.
The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized.
In addition to the life-cycle methods, this interface provides the getServletConfig method, which the servlet can use to get any startup information, and the getServletInfo method, which allows the servlet to return basic information about itself, such as author, version, and copyright.
Method Summary
void | destroy() Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. |
ServletConfig | getServletConfig() Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. |
java.lang.String | getServletInfo() Returns information about the servlet, such as author, version, and copyright. |
void | init(ServletConfig config) Called by the servlet container to indicate to a servlet that the servlet is being placed into service. |
void | service(ServletRequest req, ServletResponse res) Called by the servlet container to allow the servlet to respond to a request. |