One, tomcat
The Tomcat server is a free and open source Web application server, which is a core project in the Jakarta project of the Apache Software Foundation, jointly developed by Apache, Sun and some other companies and individuals. Thanks to Sun's involvement and support, the latest Servlet and JSP specifications are always present in Tomcat, and Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because of its advanced technology, stable performance and free, Tomcat is deeply loved by Java enthusiasts and has been recognized by some software developers. It has become a popular Web application server at present.
Tomcat is very popular among programmers because it occupies small system resources when running, has good scalability, and supports functions commonly used in developing application systems such as load balancing and mail services; Interested programmers can change it or add new features to it.
Tomcat is a small and lightweight application server. It is widely used in small and medium-sized systems and occasions where there are not many concurrent users. It is the first choice for developing and debugging JSP programs. For a beginner, think of it this way, when an Apache server is configured on a machine, it can be used to respond to requests for HTML pages. Actually the Tomcat part is an extension of the Apache server, but it runs independently, so when you run tomcat, it actually runs as a separate process from Apache.
The trick here is that, when configured correctly, Apache serves HTML pages, while Tomcat actually runs JSP pages and servlets. In addition, Tomcat, like Web servers such as IIS and Apache, has the function of processing HTML pages. In addition, it is also a Servlet and JSP container. The independent Servlet container is the default mode of Tomcat. However, Tomcat is not as good at handling static HTML as the Apache server.
Related links:
http://tomcat.apache.org/ Tomcat overview
Tomcat is a free and open source Serlvet container, which is a core project in the Jakarta project of the Apache Foundation, developed by Apache, Sun and some other companies and individuals. Thanks to Sun's participation and support, the latest Servlet and Jsp specifications are always reflected in Tomcat. Tomcat was selected by the editor of JavaWorld magazine as the most innovative java product in 2001, which shows its status in the industry.
The latest version of Tomcat is 4.0x.4.0x is different from 3.x, but redesigned. Tomcat4.0x adopts a new Servlet container: Catalina, which fully implements the Servlet2.3 and Jsp1.2 specifications. Tomcat provides versions for various platforms for download. You can download its source code version or binary version from http://jakarta.apache.org . Due to the cross-platform nature of Java, Java-based Tomcat is also cross-platform.
Unlike traditional desktop applications, an application in Tomcat is a WAR (Web Archive) file. WAR is a Web application format proposed by Sun, and similar to JAR, it is also a compressed package of many files. The files in this package are organized according to a certain directory structure: usually the root directory contains Html and Jsp files or directories containing these two files, and there is also a WEB-INF directory, which is very important. Usually there is a web.xml file and a classes directory in the WEB-INF directory, web.xml is the configuration file of the application, and the classes directory contains compiled Servlet classes and other classes that Jsp or Servlet depend on (such as JavaBean). Usually these dependent classes can also be packaged into JAR and placed in the lib directory under WEB-INF, of course, can also be placed in the CLASSPATH of the system, but it is inconvenient to transplant and manage.
In Tomcat, application deployment is very simple, you just need to put your WAR in Tomcat's webapp directory, Tomcat will automatically detect this file and extract it. When you access the Jsp of this application in the browser, it is usually very slow the first time, because Tomcat has to convert the Jsp into a servlet file and then compile it. Once compiled, access will be fast. In addition, Tomcat also provides an application: manager, a user name and password are required to access this application, and the user name and password are stored in an xml file. With this application, aided by Ftp, you can deploy and undo applications remotely via the web. Of course you can also locally.
Tomcat is not just a servlet container, it also has the function of a traditional web server: processing Html pages. But compared with Apache, its ability to handle static Html is not as good as Apache. We can integrate Tomcat and Apache, let Apache handle static HTML, and Tomcat handle Jsp and Servlet. This integration only needs to modify Apache and Tomcat configuration file.
Additionally, Tomcat provides Realm support. Realm is similar to the 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 users (similar to groups) to different applications (similar to system resources). Unauthorized users cannot access the app. Tomcat provides three kinds of Realm, 1: JDBCRealm, this Realm stores user information in the database, and obtains user information through JDBC for verification. 2: JNDIRealm, user information is stored in the LDAP-based server, and user information is obtained through JNDI. 3: MemoryRealm, user information is stored in an xml file. The manager application mentioned above uses this kind of Realm when authenticating users. Through Realm, we can easily authenticate customers who access an application.
In Tomcat4, you can also use the event listener function provided by Servlet2.3 to monitor your application or Session. Tomcat also provides other features such as integration with SSL for secure transmission. Tomcat also provides JNDI support, which is consistent with those provided by J2EE application servers. Speaking of which, we have to introduce what is the difference between what is usually called an application server (such as WebLogic) and Tomcat. The application server provides more J2EE features, such as EJB, JMS, JAAS, etc., and also supports Jsp and Servlet. Tomcat is not so powerful, it does not provide EJB and other support. But if it is integrated with JBoss (an open source application server), it can realize all the functions of J2EE. Since the application server has the function of Tomcat, is it necessary for Tomcat to exist? In fact, many of our small and medium applications do not need to use technologies such as EJB, Jsp and Servlet are enough, and it would be a waste to use an application server at this time. Tomcat is short and powerful, easy to configure, and can meet our needs. In this case, we will naturally choose Tomcat.
基于Tomcat的开发其实主要是Jsp和Servlet的开发,开发Jsp和Servlet非常简单,你可以用普通的文本编辑器或者IDE,然后将其打包成WAR即可。我们这里要提到另外一个工具Ant,Ant也是Jakarta中的一个子项目,它所实现的功能类似于Unix中的make.你需要写一个build.xml文件,然后运行Ant就可以完成xml文件中定义的工作,这个工具对于一个大的应用来说非常好,我们只需在xml中写很少的东西就可以将其编译并打包成WAR.事实上,在很多应用服务器的发布中都包含了Ant.另外,在Jsp1.2中,可以利用标签库实现Java代码与Html文件的分离,使Jsp的维护更方便。
Tomcat也可以与其它一些软件集成起来实现更多的功能。如与上面提到的JBoss集成起来开发EJB,与Cocoon(Apache的另外一个项目)集成起来开发基于Xml的应用,与OpenJMS
集成起来开发JMS应用,除了我们提到的这几种,可以与Tomcat集成的软件还有很多。
二、Jboss
JBoss是全世界开发者共同努力的成果,一个基于J2EE的开放源代码的应用服务器。 因为JBoss代码遵循LGPL许可,你可以在任何商业应用中免费使用它,而不用支付费用。JBoss支持EJB 1.1和EJB 2.0 EJB3.0的规范,它是一个管理EJB的容器和服务器。类似于Sun's J2SDK Enterprise Edition(J2EE),JBoss的目标是一个源代码开放的J2EE环境。但是JBoss核心服务仅是提供EJB服务器。JBoss不包括serverlers/JSP page 的WEB容器,当然可以和Tomcat或Jetty绑定使用。 JBoss还具有如下六大优点: 1、JBoss是免费的,开放源代码J2EE的实现,它通过LGPL许可证进行发布。 2、JBoss需要的内存和硬盘空间比较小。 3、安装非常简单。先解压缩JBoss打包文件再配置一些环境变量就可以了。 4、JBoss能够"热部署",部署BEAN只是简单拷贝BEAN的JAR文件到部署路径下就可以了。如果没有加载就加载它;如果已经加载了就卸载掉,然后LOAD这个新的。 5、JBoss与Web服务器在同一个Java虚拟机中运行,Servlet调用EJB不经过网络,从而大大提高运行效率,提升安全性能。 6、用户可以直接实施J2EE-EAR,而不是以前分别实施EJB-JAR和Web-WAR,非常方便。 JBoss的安装和配置可以直接拷贝使用,但是要改动 %JBoss-HOME%\bin\run.bat里JAVA-HOME的设置,改成本机JDK的目录。运行run.bat来启动JBoss 关闭JBoss:关闭JBoss的 DOS 窗口或按"CTRL + C" JBoss的目录结构 1、bin:开始和停止JBoss的地方。 其中有两个主要的批处理文件:run.bat和shutdown.bat。要启动JBoss只要执行run.bat文件即可;要停止JBoss必须执行shutdown.bat。 注意,shutdown.bat文件直接执行并不会自动停止JBoss,它必须要输入参数,参数意义如下: h显示帮助信息;D设置系统属性;-停止处理选项;s停止用JNDI URL指定的远程服务;n通过制定JMX名字来停止服务;a适配到指定的JNDI名称的远程服务;u指定用户名称;p指定用户密码;S停止服务器;e从虚拟机退出;H暂停。 一般,我们使用S选项来停止服务器。即执行shutdown.bat -S。 2、docs:放置JBoss的例子、测试脚本和各种脚本配置文件的DTD。 3、lib:放置JBoss所需要的部分jar包文件。 4、client:放置EJB客户端运行时所需要的jar包。 5、server:放置各启动类型的服务器端EJB配置所需要的文件等。 6、backup 以80端口服务 修改这个文件: {%JBOSS_HOME%}\server\default\deploy\jbossweb-tomcat41.sar\META-INF\jboss-service.xml 在"8080"的配置后加入以下代码 <!-- A HTTP/1.1 Connector on port 80 --> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="80" minProcessors="5" maxProcessors="100" enableLookups="true" acceptCount="10" debug="0" connectionTimeout="20000" useURIValidationHack="false"/> 重新启动JBoss就OK了 JBoss的启动过程 设置环境变量 JBOSS_CLASSPATH (可以自己加上安全管理器和xml解析器) a) %JBOSS_CLASSPATH%; b) %JAVA_HOME%/lib/tools.jar; c) run.jar d) ../lib/crimson.jar; 设置启动参数JAXP(xml解析器和相应工厂) 启动 设置配置信息 读取配置文件JBoss.properties,保存在系统属性中(System.properties) 设置缺省属性jboss.home和java.security.auth.login.config 创建MBeanServer.的实例: 把配置文件和补丁文件所在的目录指定给特定的远程类加载器Mlet 加载保存配置文件(mlet会自动在配置文件目录中查找) 初始化并启动MBean 配置服务ConfigurationService 加载配置文件 保存配置 服务控制ServiceControl 初始化服务程序(init方法) 启动服务程序(start方法) 在JBOSS中发布文件 1、制作JSP的war部署文件 用"jar cvf hello.war index.jsp main.jsp"的方式生成把index.jsp和main.jsp文件加入到hello.war中。把生成的hello.war拷贝到jboss安装目录\server\default\deploy\下,部署成功。用"http://localhost:8080/hello/"或"http://localhost:8080/hello/index.jsp"这两个地址进行测试。 2、制作Servlet的war部署文件 A、用"javac -classpath "%CLASSPATH%;%jboss_home%\server\default\lib\javax.servlet.jar" HelloWorld.java"的形式编译HelloWorld.java(这是一个Servlet)得到HelloWorld.class B、写一个web.xml配置文件 代码如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>hello.HelloWorld</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorld</servlet-name> <url-pattern>/HelloWorld</url-pattern> </servlet-mapping> </web-app> 每个标记必须小写,否则会出错。 C、先在c:\servlet下建立一个web-inf目录,在目录中放入web.xml文件。 D、在web-inf目录下建立一个classes目录,放入编译好的HelloWorld.class文件 E、在c:\servlet下执行jar cvf hello.war *.*,很快就生成了一个名为hello.war的文件,接着把hello.war复制到jboss的安装目录\server\default\deploy\下完成部署。 3、也可以不打包,把文件放在deploy下的同名文件夹下也可以。比如原来是制作成hello.war文件,可以建立一个名称为hello.war的文件夹,把要发布的文件拷贝到这个目录底下也可以发布成功。 补充 1、JBoss的默认端口是8080 3、对于NT和Win2000系统如果你要安装NT或Win2000服务的话,可以把JBoss加在系统服务中,避免你每次需要到JBoss目录下运行run.bat命令,只是当系统启动时,自动启动JBoss服务器。 三、weblogic
|