Development environment required for compiling Servlet
The basic environment required for Servlet development is JSDK and a Web server supporting Servlet.
1. JSDK (Java Servlet Development Kit)
The JSDK contains the Java class libraries and related documents required for compiling Servlet applications. For users who use Java 1.1 for development, JSDK must be installed. JSDK has been integrated into Java 1.2 Beta. If you use Java 1.2 or later for development, you do not have to install JSDK.
The JSDK can be downloaded free of charge at your oft website. Its address is: http://www.sun.com/software/jwebserver/redirect.html.
2. Web servers supporting Servlet
Servlet needs to run on the Web server that supports Servlet. Currently, JSWDK1.0.1 of the Servlet Web Server SUN is supported. If the existing Web server does not support Servlet, you can use some third-party vendor's server add-ons to make the Web server support Servlet, which Live Software (http://www.livesoftware.com) a product called JRun is provided. by installing the corresponding JRun version, Microsoft IIS and Netscape Web Server can support Servlet.
Servlet Development Process
The following is a simple Servlet example to illustrate the Servlet development process.
1. Write Servlet code
Java Servlet API is a standard Java extension Package, which contains two packages: javax. servlet and javax. servlet. http. For developers who want to develop user-defined protocols, they should use javax. the class and interface in the servlet package. for developers who only use the HTTP protocol to interact with the client, they only need to use javax. servlet. develop the class and interface in the http package.
The following is a servlet program code (RequestInfoExample. java ):
- import java.io.*;
- import java.servlet.*;
- import javax.servlet.*;
-
- public class RequestInfoExample extends HttpServlet {
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException
- {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- out.println("<html>");
- out.println("<body>");
- out.println("<head>");
- out.println("<title>Request Information Example</title>");
- out.println("</head>");
- out.println("<body>");
- out.println("<h3>Request Information Example</h3>");
- out.println("Method: " + request.getMethod());
- out.println("Request URI: " + request.getRequestURI());
- out.println("Protocol: " + request.getProtocol());
- out.println("PathInf " + request.getPathInfo());
- out.println("Remote Address: " + request.getRemoteAddr());
- out.println("</body>");
- out.println("</html>");
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse res)
- throws IOException, ServletException
- {
- doGet(request, response);
- }
- }
- Wizard for creating Servlet Filters
- Install Servlet and JSP development tools
- Extended Future Response Servlet
- Servlet Container matching process
- User cache Servlet