From the early stages of the network, people hope that their network servers will not only display static documents, but also the general Gateway Interface (CGI) expands the server capabilities, however, the cost is that additional processing processes are added. FastCGI tightly integrates external CGI processing processes with network servers. In addition, for server APIs such as NSAPI and ISAPI, they directly integrate external processes into the server in the form of server plug-ins. Now with Java Servlets, they are powerful and can quickly replace your existing CGI programs.
What is Servlets?
Just as the applet expands the capabilities of the web browser, the Java component Servlets expands the capabilities of the network server. For processing on any type of server, Servlets can be used as a server-side pair des or as a CGI program (which can be used as a plug-in the Java Web server of JavaSoft. Servlets can be transplanted. Unlike CGI and proprietary API modules, you can use Java's "write once, run everywhere" mechanism to configure network applications in your enterprise. The operation of Servlets is also very stable. You have created a database connection in the Servlet. The connection still exists when you access the Servlet next time, which is different from that of CGI programs. Servlets is also scalable, so you can use object-oriented programming methods to reduce development time. Servlets can run on any Servlet-supported network server. Currently, the Servlet SDK not only supports Java Web server of JavaSoft, but also supports Netscape, Apache, IIS, and a large number of third-party network servers.
Run your Servlet
Once the Servlet is compiled and compiled successfully, you can put it in the Servlet alias directory on the network server. Just like the cgi-bin alias directory on the server, any file in the Servlet directory will be executed as Servlets once requested as part of the url. For example, BasicCGIServlet can be called through the following url: http://mycompany.com/servlet/basiccgiservlet. You can call this url directly (and send a request keyword/value pair string to the Servlet) or call it through an action in the HTML form. For more information about Servlet-supported network servers, see the relevant documentation in JSDK.
Further usage
GenericServlet and HttpServlet provide a fixed base class for building Servlets. By using the overload service () method, you can build on them. For example, you can add support for response caching. For more information, see getLastModified () in HttpServlet, and support for HTTP 1.1 methods. You can even build an extended template engine. Who really like built-in HTML code in their programs ?)
In addition to the standard application/x-www-form-urlencoded mime type, JSDK is extended to support form encoding of other types. For example, you can add support for multipart/form-data mime types to process uploaded files through HTTP. Interface methods such as getParameterNames () and getParameterValues () are implemented in the sun. Servlet package. Therefore, you need to configure JSDK to add these support. There is also a work und that you can implement on your own, but to do so, you need to copy the code or change the semantics of the JSDK. The above methods are all feasible, but none of them are perfect.
Conclusion
Now you should create Java Servlets by yourself, which can be used to replace traditional Perl and C/C ++ CGI programs. The object-oriented features of Java and the mechanism of "writing once and running everywhere" make Java Servlets easy to write. Servlet stability can solve status management problems, and these are common problems that are solved by using only one CGI program. Servlets can use all Java functions, including JDBC and RMI. Because most network servers support Servlet, Java will quickly become an optional language for developing enterprise-level applications.
- Servlet Container session tracking
- Detailed description of Servlet instances
- Introduction to Servlet read request headers
- Call the Http Servlet Request Method
- Basic Structure of Servlet