Web development light platform - Tomcat (Introduction)
Today, more and more web applications, the traditional HTML has not satisfied today's needs. We need a interactive web, so we have born a variety of web languages. Such as ASP, JSP, PHP, etc. Of course, these languages have a close relationship with traditional languages, such as PHP based on C and C languages, JSP based on Java language. The Tomcat to be introduced in this article is a JSP and Servlet running platform. One: What is JSP and Servlet? JSP (JavaServer? Page) is an Script of Java code in ordinary HTML, at this point, which is the same as other scripting languages (such as PHP), but it is with other languages Different: Other scripting languages explain this script directly by the server, while JSP is converted by JSP container (such as Tomcat) to servlet, then call Javac to compile servlet into a Class file. Finally, the server explains the class file. So what is servlet? The servlet is actually a special Java class. The servlet class is generally inherited from the HTTPservlet class. At least the Doget or Dopost function is to be implemented in this class, and the request from the customer is handled in these two functions, and then returns the result. Servlet and JSP are important part of the Sun J2EE architecture. Since it is based on Java language, it is convenient to call a powerful Java® API (such as JDBC). 2: Tomcat Overview? Tomcat is a free open source Servervet container, which is a core item in the Jakarta project of the Apache Foundation, developed by Apache, Sun and other companies and individuals. Due to the participation and support of Sun, the latest servlet and JSP specification are always reflected in Tomcat. Tomcat is selected as the most innovative Java product in 2001 by the editor of JavaWorld Magazine, which shows its position in the industry. ? Tomcat? The latest version is 4.0X. 4.0X is different from the 3.x architecture, but redesigned. New servlet containers in Tomcat 4.0x: Catalina, complete Servlet2.3 and JSP1.2 specifications. Tomcat provides versions of various platforms for download, which can be downloaded from http://jakarta.apache.org to download their source code or binary. Due to Java's cross-platform characteristics, Java-based Tomcat also has cross-platform. • Unlike traditional desktop applications, the application in Tomcat is a WAR (Web® Archive) file. WAR is a web application format proposed by Sun, similar to JAR, is also a compressed package for many files. The files in this package are organized by a certain directory structure: usually contains HTML and JSP files with HTML and JSP files or include the directory of these two files, and there will be a web-inf directory, which is important. Usually there is a web.xml file and a class directory in the web-inflicide directory, web.xml is the configuration file for this application, and the classes directory contains compiled servlet classes and other classes dependen on by JSP or servlets (such as Javabean. Usually these dependencies can also be packaged into a JAR in the lib directory under Web-INF, and of course it can also be placed in the system's classpath, but it is not convenient to transplant and manage.
In Tomcat, the deployment of the application is simple, you just put your WAR in the Tomcat's WebApp directory, Tomcat automatically detects this file and decompressed it. When you visit the JSP of this app in your browser, you will usually be very slow, because Tomcat is transformed into a servlet file and then compile. After compiling, the access will be very fast. In addition, Tomcat also provides an application: Manager, accessing this app requires username and password, username, and password stored in an XML file. With this application, assist in FTP, you can deploy and revoke applications remotely through web. Of course, you can also. Tomcat is more than just a servlet container, which also has a function of traditional web servers: Handling an HTML page. But compared to Apache, its ability to treat static HTML is not as good as Apache. We can integrate Tomcat and Apache to a piece, let Apache processes static HTML, while Tomcat processes JSP and servlet. This integration only needs to modify the Apache and Tomcat configuration files. • In addition, Tomcat provides Realm support. Realm is similar to Group in UNIX. In UNIX, a group corresponds to a certain resource of the system, and a group cannot access resources that do not belong to it. Tomcat uses Realm to assign different applications (similar system resources) to different users (similar to Group). Users who have no permissions cannot access this app. Tomcat provides three realm, 1: JDBCREALM, which exists in the database, and obtains user information through the JDBC to verify. 2: JNDIREALM, the user information exists in an LDAP-based server, and obtains user information through JNDI. 3: MemoryRealm, the user information There is an XML file, and the Manager application to the Manager app verifies the user to use this Realm. With Realm, we can easily verify the customers who visit an application. In Tomcat4, you can also use the event listener function provided by servlet 2.3 to monitor your application or session. Tomcat also provides some other features, such as integrated with SSL to a piece of secure transmission. There is also Tomcat also provides JNDI support, which is consistent with those J2EE application servers. Speaking here, we have to introduce what is the difference between the usual application server (such as WebLogic) and Tomcat. Application servers provide more J2EE features, such as EJB, JMS, JaaS, etc., and also support JSP and servlets. The Tomcat is not so powerful, it does not provide EJB and other support. However, if you integrate with JBoss (an open source application server), all of the functions of J2EE can be implemented. Since the application server has the function of Tomcat, is Tomcat if there is existence? In fact, many of our small and medium-sized applications don't need to adopt EJB, JSP and servlets are enough, then if you use the application server, it is a waste. And Tomcat is short, and the configuration is convenient, we can meet our needs. In this case, we will naturally choose Tomcat. Tomcat-based development is actually the development of JSP and Servlet, develop JSP and servlets very simple, you can use a normal text editor or IDE, then package it into WAR.