一、整合二者
(1)用mod_jk2-2.0.43.dll拷進apache2/modules/
(2)編輯apache2/conf/workers2.properties
其內容:
# Define the communication channel
[channel.socket:localhost:8009]
info=Ajp13 forwarding over socket
tomcatId=localhost:8009
# Map the Tomcat examples webapp to the Web server uri space
[uri:/examples/*]
info=Map the whole webapp
(3)編輯tomcat41/conf/jk2.properties
其內容:
# The default port is 8009 but you can use another one
# channelSocket.port=8019
(4)httpd.conf中加入
LoadModule jk2_module modules/mod_jk2-2.0.43.dll
二、設置tomcat4.1.12
(1)編輯tomcat41/conf/server.xml
在</Context>和</Host>中間加入:
<Context path="/yourapp" debug="0" docBase="yourapp" reloadable="true"/>(yourapp目錄放在tomcat41/webapps下)
或
<Context path="/yourapp" debug="0" docBase="/yourapp" reloadable="true"/>(yourapp目錄放在tomcat41/webapps/ROOT下)
(2)把tomcat41/webapps/examples下的web-inf目錄複製到yourapp下。
然後把你的bean複製到tomcat/common/classes下。
<引用>寫好了Bean放哪裡?首先我們要講一下Java尋找類的方法,Java是根據Classpath中的路徑去找的,首先找當前路徑,然後是其他路徑,而由於Jsp也是在JVM上執行因此也是根據Classpath去找。在Tomcat3.3以前的版本(不包含3.3),你只要把你的類路徑放在Classpath中,或者是包的檔案路徑。就可以找到,而在3.3以後的版本,他在.bat批次處理檔案中自動設置Classpath,如4.0,類可以放在tomcat/common/classes下面,而Jar包可以放在tomcat/common/lib下面,系統自動Load。</引用>
(3)(有了上一步,這步可以不做)編輯tomcat41/bin/setclasspath.bat
在set CLASSPATH=%JAVA_HOME%\lib\tools.jar後加入一行:
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\webapps\yourapp\WEB-INF\jsp\beans(注意大小寫)
三、設置apache2.0.43
編輯httpd.conf:
(1)註釋掉AddDefaultCharset ISO-8859-1
加AddDefaultCharset GB2312 //解決不自動顯示中文
DefaultLanguage GB2312
AddLanguage zh-cn .cn
在頁面中加:
<%@ page contentType="text/html; charset=gb2312" %>
和
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
(2)DirectoryIndex index.html index.jsp index.htm index.html.var在這行加入index.jsp
(3)虛擬主機
<VirtualHost localhost> //注意這裡的localhost
ServerAdmin
yao@yao.com
DocumentRoot c:\tomcat4.1\webapps //你的yourapp目錄的父目錄
ServerName localhost //注意這裡的localhost
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
mod_jk2-2.0.43.dll的下載地:
http://jakarta.apache.org/builds/jak...jk2-2.0.43.dll
單一整合apache2.0.43跟tomcat4.1.12是完全可以的,但真正的商務應用中往往是採用apache+N個tomcat instance實現load balance,對於linux(redhat8.0)下試驗了N次,好不容易編譯通過了Jk2,在實現負載平衡時卻出了點問題,無論怎樣配置,mod_jk的session affinity特性丟失,試驗了N次,甚至分析了mod_jk2的源碼還是找不到原因,而且mod_jk2的資料極少
所以最後還是採用了apache2+mod_jk1.2+tomcat4實現load balance,目前可能是最有價值的jsp/servlet架構,當然如果利用javagroup完全可以在tomcat instance之間實現session replication,這樣的話就不用擔心某個tomcat down掉了,Jboss實現cluster就是採用的javagroups的底層代碼
相當具有潛力免費的J2EE架構apache+tomcat+jboss,就是文檔比較少