免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2077 | 回复: 0
打印 上一主题 下一主题

Apache 2.2 + Tomcat 6.0 + MySQL 5.0 + mod_jk 整合 [复制链接]

论坛徽章:
5
寅虎
日期:2015-01-20 09:16:52亥猪
日期:2015-01-21 14:43:44IT运维版块每日发帖之星
日期:2015-12-17 06:20:00每日论坛发贴之星
日期:2015-12-17 06:20:00每周论坛发贴之星
日期:2015-12-20 22:22:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-08 09:43 |只看该作者 |倒序浏览

                                Apache 2.2 + Tomcat 6.0 + MySQL 5.0 + mod_jk 整合                   For more articles, please visit http://www.l-penguin.idv.tw/作者:廖子儀 (Tzu-Yi Liao)Certified:LPIC Level I、LPIC Level II、RHCEE-mail:steven@ms.ntcb.edu.twWeb site:Steven's Linux Note (http://www.l-penguin.idv.tw/)
在前一篇Apache 及 Tomcat 的結合(New window) 的文件中,說明了使用mod_jk2 把 Apache 與 Tocmat 相結合的實例。最近小弟遇到了主機的擴充案,重新調整了 Apche 的編譯,並且使用新版本的 Tomcat Connectors JK 1.2.26版本來做兩者之間的溝通。本篇文章同時也介紹了 Tomcat 6.0 的 MySQL Connection Pool 用法(同時適用於 Tomcat 5.5),實做中也提及如何測試資料庫的連線。此文章與前一篇Apache 及 Tomcat 的結合(New window) 並不相容,Tomcat 3 和Tomcat 5.5 的 Connection Pool 用法已不同;而 mod_jk2 也不再維護,Tomcat組織以 mod_jk 為主要的發展對像,所以在這些改變之下,決定重新寫此篇文件以供大家參考,若有不明或有誤的地方請大家提出。架構

使用者在瀏覽網站時,是對應到 Apache Server,而 JSP 程式則是放在 Tomcat主機上,當然了資料庫也是獨立的。使用這種架構可分散網頁檔案與程式之間的損失風險。
架構設計之初,應避免把應用伺服器與 資料庫伺服器暴露在網路之中,可以選擇使用內部的虛擬 IP 或防火牆來防止使用者可任意尋找露洞的機會。當然了,安全性的研究不在本次的議題裡,大家可以參閱查詢相關資料。以下 IP 為本次的實例分配:· Apache:192.168.1.205(Apache 2.2.9,Tomcat Connector 1.2.26)· Tomcat:192.168.1.207(Tomcat 6.0.16)· MySQL:192.168.1.204(MySQL 5.0.45)
Apache 服務要完成整個 Apache 伺服器的設定,需要下例套件配合:· Sun Java JDK(Java version 1.6.0_06)· Apache(httpd 2.2.9)· Tomcat(tomcat 6.0.16)· Tomcat Connector(Tomcat Connector 1.2.26)以下會逐一說明。下載安裝 Apache下載 Apache 並解壓縮最新版本的 Apache 可以到 Apache 官方網站下載:http://httpd.apache.org/root # wget http://apache.cdpa.nsysu.edu.tw/httpd/httpd-2.2.9.tar.bz2root # tar -jxvf httpd-2.2.9.tar.bz2編譯 httpd若是採用此方式,在您的環境中必需要有 gcc 編譯器root # cd httpd-2.2.9root # ./configure --prefix=/usr/local/httpd --with-mpm=worker> --enable-cache --enable-file-cache --enable-disk-cache> --enable-mem-cache --enable-mime-magic --enable-headers> --enable-ssl --enable-http --enable-cgi --enable-rewrite> --enable-so --with-suexec-gidmin --with-suexec-logfileroot # makeroot # make install以 上編譯到安裝的過程可能需要一段時間, 結束之後 httpd 會安裝到/usr/local/httpd 目錄,使用下例指可以啟動 http 服務,即可使用瀏覽器聯結。root # /usr/local/httpd/bin/apachectl start查看 httpd 是否有啟動並設定連接埠。root # ps aux | grep httpd; netstat -ntulp | grep :80root 3021 0.0 0.7 7908 2808 ? Ss 18:55 0:00/usr/local/httpd/bin/httpd -k startdaemon 3022 0.0 0.4 7512 1648 ? S 18:55 0:00/usr/local/httpd/bin/httpd -k startdaemon 3023 0.0 0.7 284680 2904 ? Sl 18:55 0:00/usr/local/httpd/bin/httpd -k startdaemon 3024 0.0 0.7 284680 2856 ? Sl 18:55 0:00/usr/local/httpd/bin/httpd -k startdaemon 3035 0.0 0.7 284680 2904 ? Sl 18:55 0:00/usr/local/httpd/bin/httpd -k startdaemon 3200 0.0 0.7 284680 2836 ? Sl 18:57 0:00/usr/local/httpd/bin/httpd -k startroot 3824 0.0 0.1 1820 484 pts/0 S+ 22:16 0:00 grep httpdtcp 0 0 :::80 :::*LISTEN 3021/httpd下載安裝 Tomcat、Sun Java JDK 與 Tomcat ConnectorTomcat 可到http://tomcat.apache.org/ 下 載、Tomcat Connector 可到http://tomcat.apache.org/download-connectors.cgi 下載,本例中 Java JDK 是採用Sun 所發展的 Sun Java JDK,可至http://java.sun.com/javase/downloads/index.jsp下載 JDK 即可。下載 Tomcat Connectorroot # wgethttp://apache.cdpa.nsysu.edu.tw/tomcat/tomcat-connectors/jk/source/jk-1.2.26/tomcat-connectors-1.2.26-src.tar.gz下載 Sun Java JDKroot # lynx'http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u6-linux-i586.bin?BundledLineItemUUID=fR9IBe.pEDAAAAEaAgAocbiQ&OrderID=YtFIBe.pnk8AAAEa9_8ocbiP&ProductID=VXZIBe.ootIAAAEZTrBAkQve&FileName=/jdk-6u6-linux-i586.bin'下載 Tomcatroot # wgethttp://apache.stu.edu.tw/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.tar.gz搬移檔案至 /opt 目錄root # mv apache-tomcat-6.0.16.tar.gztomcat-connectors-1.2.26-src.tar.gz jdk-6u6-linux-i586.bin /opt/解壓縮檔案root # tar -zxvf apache-tomcat-6.0.16.tar.gz ; tar -zxvftomcat-connectors-1.2.26-src.tar.gz ; chmod +x jdk-6u6-linux-i586.bin設定與安裝 Tomcat、Tomcat Connector 與 Sun Java JDK安裝 Sun Java JDKroot # ./jdk-6u6-linux-i586.binSun Microsystems, Inc. Binary Code License Agreementfor the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THESOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITIONTHAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARYCODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE TERMS(COLLECTIVELY "AGREEMENT"). PLEASE READ THE AGREEMENTCAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOUACCEPT THE TERMS OF THE AGREEMENT. INDICATE ACCEPTANCE BYSELECTING THE "ACCEPT" BUTTON AT THE BOTTOM OF THEAGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY ALL THETERMS, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THEAGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL NOTCONTINUE.1. DEFINITIONS. "Software" means the identified above inbinary form, any other machine readable materials(including, but not limited to, libraries, source files,header files, and data files), any updates or errorcorrections provided by Sun, and any user manuals,programming guides and other documentation provided to you--More--~~~~~~~~~~~~~~~~~ignore~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~THIRDPARTYLICENSEREADME.txt file, the disclaimer ofwarranty and limitation of liability provisions inparagraphs 5 and 6 of the Binary Code License Agreementshall apply to all Software in this distribution.H. Termination for Infringement. Either party may terminatethis Agreement immediately should any Software become, orin either party's opinion be likely to become, the subjectof a claim of infringement of any intellectual propertyright.I. Installation and Auto-Update. The Software'sinstallation and auto-update processes transmit a limitedamount of data to Sun (or its service provider) about thosespecific processes to help Sun understand and optimizethem. Sun does not associate the data with personallyidentifiable information. You can find more informationabout the data Sun collects at http://java.com/data/.For inquiries please contact: Sun Microsystems, Inc., 4150Network Circle, Santa Clara, California 95054, U.S.A.Do you agree to the above license terms? [yes or no]yes~~~~~~~~~~~~~~~~~~~ignore~~~~~~~~~~~~~~~~~~~~~``Java(TM) SE Development Kit 6 successfully installed.Product Registration is FREE and includes many benefits:* Notification of new versions, patches, and updates* Special offers on Sun products, services and training* Access to early releases and documentationProduct and system data will be collected. If your configurationsupports a browser, the Sun Product Registration form forthe JDK will be presented. If you do not register, none ofthis information will be saved. You may also register yourJDK later by opening the register.html file (located inthe JDK installation directory) in a browser.For more information on what data Registration collects andhow it is managed and used, see:http://java.sun.com/javase/registration/JDKRegistrationPrivacy.htmlPress Enter to continue.....Done.安裝 Tomcatroot # mv apache-tomcat-6.0.16 tomcat; mv jdk1.6.0_06/ java設定環境變數在安裝 mod_jk 之前,需先設定 tomcat 與 java 的目錄,可在 /etc/profile 設定。JAVA_HOME=/opt/javaCATALINA_HOME=/opt/tomcatCATALINA_BASE=/opt/tomcatCLASSPATH=./:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib/ext:${CATALINA_HOME}/common/libexport JAVA_HOME CATALINA_HOME CATALINA_BASE CLASSPATHexport PATH=${JAVA_HOME}/bin:${CATALINA_HOME}/bin:${PATH}設定完成後可使用 source 指令或 . 指令讓修改的項目生效。root # . /etc/profile編譯安裝 mod_jk完成以上設定後,即可開始編譯 mod_jk。編譯 mod_jkroot # cd tomcat-connectors-1.2.26-src/native/root # ./configure --with-java-home=/opt/java--with-apxs=/usr/local/httpd/bin/apxsroot # make安裝 mod_jk.so 至 httpdroot # cp apache-2.0/mod_jk.so /usr/local/httpd/lib/以上完成編譯安裝之後,就可以開始設定 apache,讓 mod_jk 生效。apache 的設定檔在 /usr/local/httpd/conf/ 目錄下。設定 Apche 與 mod_jk編輯 httpd.conf在 httpd.conf 中加入載入 mod_jk 模組與 mod_jk 設定檔項目。LoadModule jk_module lib/mod_jk.so# mod_jk settingsInclude conf/mod_jk.conf在 /usr/local/httpd/conf/ 目錄加入 mod_jk.confroot # touch mod_jk.conf在 mod_jk.conf 加入以下內容#setup the workers.properties file path, default prefix path is httpd'shome (/usr/local/httpd)JkWorkersFile conf/workers.propertiesJkLogFile /var/log/jk.logJkShmFile /var/log/jk-runtime-statusJkLogLevel errorJkLogStampFormat "[%a %b %d %H:%M:%S %Y] "JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectoriesJkRequestLogFormat "%w %V %T"# Sample JkMounts. Replace these with the paths you would# like to mount from your JSP server.# syntax: JkMount ${URL_DIR}/*.jsp worker_nameJkMount /project1/*.jsp jsp-ap207JkMount /project2/*.jsp jsp-ap207JkMount /project3/*.jsp jsp-ap207增加conf/workers.properties 檔案root # touch /usr/local/httpd/conf/workers.properties設定 workers.properties# BEGIN workers.properties# setting tomcat_home and java_homeworkers.tomcat_home=/opt/tomcatworkers.java_home=/opt/java# worker.list defined worker_name, used by mod_jk.confworker.list=jsp-ap207worker.jsp-ap207.port=8009worker.jsp-ap207.host=192.168.1.207worker.jsp-ap207.type=ajp13worker.jsp-ap207.lbfactor=1重新啟動 Apache經過了以上步驟後,在 Apache 的部份可說是已完成設定(當然細項目份還需要調整)。現在可重新啟動 Apache。root # /usr/local/httpd/bin/apachectl stoproot # /usr/local/httpd/bin/apachectl startTomcat 服務要完成整個 Tomcat 的設定,需要以下套件配合· Tomcat(http://tomcat.apache.org/)· Java JDK(http://java.sun.com/javase/downloads/index.jsp)· jaf(http://java.sun.com/javase/technologies/desktop/javabeans/jaf/downloads/index.html)· javamail(http://java.sun.com/products/javamail/downloads/index.html)下載與安裝 Tomcat、Java JDK、jaf 與 javamail下載 Tomcatroot # wgethttp://apache.stu.edu.tw/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.tar.gz下載 Sun Java JDKroot # lynx'http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u6-linux-i586.bin?BundledLineItemUUID=fR9IBe.pEDAAAAEaAgAocbiQ&OrderID=YtFIBe.pnk8AAAEa9_8ocbiP&ProductID=VXZIBe.ootIAAAEZTrBAkQve&FileName=/jdk-6u6-linux-i586.bin'下載 jafroot # lynx'http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jaf-1_0_2-upd2.zip?BundledLineItemUUID=WoRIBe.m5QUAAAEaKzlGV8Li&OrderID=VYdIBe.mwygAAAEaHzlGV8Li&ProductID=J_vACUFBIFEAAAEYeEo5AXiq&FileName=/jaf-1_0_2-upd2.zip'下載 javamailroot # lynx'http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/javamail-1_4_1.zip?BundledLineItemUUID=n7RIBe.mEw8AAAEavaVGV8Lk&OrderID=iOdIBe.mpdYAAAEarqVGV8Lk&ProductID=3v_ACUFBMTsAAAEYxBQ5AXuF&FileName=/javamail-1_4_1.zip'解壓縮檔案root # tar -zxvf apache-tomcat-6.0.16.tar.gz ;unzip jaf-1_0_2-upd2.zip ;unzip javamail-1_4_1.zip; chmod +x jdk-6u6-linux-i586.binroot # ./jdk-6u6-linux-i586.binSun Microsystems, Inc. Binary Code License Agreementfor the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THESOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITIONTHAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARYCODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE TERMS(COLLECTIVELY "AGREEMENT"). PLEASE READ THE AGREEMENTCAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOUACCEPT THE TERMS OF THE AGREEMENT. INDICATE ACCEPTANCE BYSELECTING THE "ACCEPT" BUTTON AT THE BOTTOM OF THEAGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY ALL THETERMS, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THEAGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL NOTCONTINUE.1. DEFINITIONS. "Software" means the identified above inbinary form, any other machine readable materials(including, but not limited to, libraries, source files,header files, and data files), any updates or errorcorrections provided by Sun, and any user manuals,programming guides and other documentation provided to you--More--~~~~~~~~~~~~~~~~~ignore~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~THIRDPARTYLICENSEREADME.txt file, the disclaimer ofwarranty and limitation of liability provisions inparagraphs 5 and 6 of the Binary Code License Agreementshall apply to all Software in this distribution.H. Termination for Infringement. Either party may terminatethis Agreement immediately should any Software become, orin either party's opinion be likely to become, the subjectof a claim of infringement of any intellectual propertyright.I. Installation and Auto-Update. The Software'sinstallation and auto-update processes transmit a limitedamount of data to Sun (or its service provider) about thosespecific processes to help Sun understand and optimizethem. Sun does not associate the data with personallyidentifiable information. You can find more informationabout the data Sun collects at http://java.com/data/.For inquiries please contact: Sun Microsystems, Inc., 4150Network Circle, Santa Clara, California 95054, U.S.A.Do you agree to the above license terms? [yes or no]yes~~~~~~~~~~~~~~~~~~~ignore~~~~~~~~~~~~~~~~~~~~~``Java(TM) SE Development Kit 6 successfully installed.Product Registration is FREE and includes many benefits:* Notification of new versions, patches, and updates* Special offers on Sun products, services and training* Access to early releases and documentationProduct and system data will be collected. If your configurationsupports a browser, the Sun Product Registration form forthe JDK will be presented. If you do not register, none ofthis information will be saved. You may also register yourJDK later by opening the register.html file (located inthe JDK installation directory) in a browser.For more information on what data Registration collects andhow it is managed and used, see:http://java.sun.com/javase/registration/JDKRegistrationPrivacy.htmlPress Enter to continue.....Done.將檔案移動到 /opt 目錄root # mv apache-tomcat-6.0.16 /opt/tomcat; mv jaf-1.0.2/ /opt/jaf; mvjavamail-1.4.1/ /opt/javamail; mv jdk1.6.0_06/ /opt/java以上過程會把 Tomcat、jaf、javamail 與 Sun Java JDK 安裝完成,現在必需設定系統變數才可使 tomcat 順利啟動。編輯 /etc/profile 檔案,並加入以下設定。JAVA_HOME=/opt/javaCATALINA_HOME=/opt/tomcatCATALINA_BASE=/opt/tomcatCLASSPATH=./:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib/ext:${CATALINA_HOME}/common/lib:/opt/javamail/mail.jar:/opt/jaf/activation.jarexport JAVA_HOME CATALINA_HOME CATALINA_BASE CLASSPATHexport PATH=${JAVA_HOME}/bin:${CATALINA_HOME}/bin:${PATH}完整的設定 /etc/profile 之後執行下列指令可立即生效。root # . /etc/profile完成以上項目後,即可開始設定 tomcat,讓 tomcat 接受處理 Apache 的請求。設定 tomcat以下說明的 tomcat 設定檔均指 /opt/tomcat/conf/server.xml 檔案,若您的 tomcat安裝在不同路徑請自行更改。處理 Apache 所指示的檔案,需要 tomcat 的配合,預設 tomcat 開啟 8009 連接埠的請求,因此只需要設定虛擬目錄即可。設定 http://192.168.1.205/project1 目錄,設定時先先定議一個虛擬網站,再設定虛擬目錄,虛擬網站由  的 xml 標籤所包含,而目錄是以 所包含,其格式如下:server.xml 修改過後的樣式如下:unpackWARs="true" autoDeploy="true">debug="5" reloadable="true" crossContext="true">以上  標籤裡的 path 屬性是指 URL 的路徑,實際對應的目錄為/projects/project1/。設定完成後,請先行建立 /projects/project1/ 目錄。root # mkdir -p "/projects/project1"; cd /projects/project1啟動 tomcat 服務。root # /opt/tomcat/bin/startup.shUsing CATALINA_BASE: /opt/tomcatUsing CATALINA_HOME: /opt/tomcatUsing CATALINA_TMPDIR: /opt/tomcat/tempUsing JRE_HOME: /opt/java測試完成了以上 Apache 與 Tomcat 的設定,現在可進行測試,請先在 Tomcat 主機上的 /projects/project1/ 建立一個 hello.jsp 程式,內容如下。String str1="Hello World!";out.println(str1);%>hello.jsp 程式可點選此處下載。現在,開啟您的瀏覽器,輸入 http://192.168.1.205/project1/hello.jsp 網址。

MySQL 設定MySQL 設定的方式很簡單,基乎不需要任何的設定,只要確定可以連線到資料庫即可。在 Tomcat 伺服器上,測試 MySQL 連線方如下:steven $ mysql -u steven -p -h 192.168.1.204Enter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 443 to server version: 5.0.22-logType 'help;' or 'h' for help. Type 'c' to clear the buffer.mysql>以上若可順利連線到 MySQL 主機則表示成功。若是連線失敗,請檢查防火牆設定與 MySQL 是否有啟動。安裝 MySQL Connection/J要使 tomcat 與 MySQL 可以做資源聯結,需要有 MySQL Connector/J 的配合才行,可到 MySQL 網站(http://dev.mysql.com/downloads/connector/j/)中下載。本文編寫時,最新版本的 Connector/J 為 5.1.6 版。root # lynx'http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.6.tar.gz/from/http://mysql.ntu.edu.tw/'root # tar -zxvf mysql-connector-java-5.1.6.tar.gz下載完後,把 mysql-connector-java-5.1.6-bin.jar 複製到 /opt/tomcat/common/lib/裡即可注意:mysql-connector-java-5.1.7-bin.jar 放到/opt/tomcat/lib下面建立相应的数据库文档是project1这个数据库,把mysql服务启动(这是gamester88做的时候碰到的问题)root # cpmysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar/opt/tomcat/common/lib/編輯 Tomcat 設定檔設定 Tomcat Database Connection Pool 的方式很簡單,只要在目錄裡加上 標籤即可,使用的方式如下:把  標籤放在  裡,則此目錄的程式都可以引用在此設定的資料庫連線資源,以下為實際修改方式:unpackWARs="true" autoDeploy="true">debug="5" reloadable="true" crossContext="true">type="javax.sql.DataSource"maxActive="100" maxIdle="30" maxWait="10000"username="steven" password="pass"driverClassName="com.mysql.jdbc.Driver"url="jdbc:mysql://192.168.1.204:3306/project1?autoReconnect=true"/>在  標籤裡的 name 是指資料庫資源名稱,username 與 password為連線的帳號與密碼,而 url 裡設定了所要連結的資料庫主機與資料庫名稱。當然您必需把 project1 這個資料庫先建立起來並設定 steven 帳號可以存取才行。注意:您可以同時設定多個 Resource 資源,只要 name 不重複即可。設定完成後,需重新啟動 tomcat 伺服器。閉關 tomcatroot # /opt/tomcat/bin/shutdown.shUsing CATALINA_BASE: /opt/tomcatUsing CATALINA_HOME: /opt/tomcatUsing CATALINA_TMPDIR: /opt/tomcat/tempUsing JRE_HOME: /opt/java啟動 tomcatroot # /opt/tomcat/bin/startup.shUsing CATALINA_BASE: /opt/tomcatUsing CATALINA_HOME: /opt/tomcatUsing CATALINA_TMPDIR: /opt/tomcat/tempUsing JRE_HOME: /opt/java測試 JSP 連線請在 /projects/project1/ 裡建立 db_test.jsp,而 db_test.jsp 的內容如下:Test of mysql connection poolout.print("start");try{Context initctx = new InitialContext();Context ctx = (Context) initctx.lookup("java:comp/env");Object obj = (Object) ctx.lookup("jdbc/project1");javax.sql.DataSource ds = (javax.sql.DataSource)obj;Connection conn = ds.getConnection();out.print("mysql connection pool runs perfectly!");conn.close();}catch(Exception ex){out.print(ex.getMessage());ex.printStackTrace();}%>請注意,以上 jsp 裡 ctx.lookup 裡所指定的 jdbc 為 tomcat 設定檔裡的 名稱,與 name 屬性相對應。以上 db_test.jsp 可以點選此處下載。開啟瀏覽器,輸入測試程式的網址,若是連線成功則會出現 mysql connectionpool runs perfectly! 字樣。

               
               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/71666/showart_1921999.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP