Apache2.0.43+Tomcat4.1.18+J2sdk1.4.1+Sql2000连接池配置 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
一、 所用文件 1、 apache_2.0.43-win32-x86-no_ssl.msi——apache2.0.43web服务器; 2、 j2sdk-1_4_1_02-windows-i586.exe ——jdk1.4.1; 3、 mod_jk-2.0.43.dll——Apache和Tomcat结合所需的链接文件; 4、 tomcat-4.1.18.exe——应用服务器tomcat4.1.18; 5、 W2Ksp3.exe——jdk1.4必须的Win2000补丁; 6、 jdbcmssql.rar——解压缩后为SqlServer的jdbc驱动包; 二、 安装目录 注:如果不想再次修改配置文件,就要按以下目录进行安装,注意大小写。 1、 安装win2000补丁; 2、 安装j2sdk-1_4_1_02-windows-i586.exe到d:\j2sdk1.4.1; 3、 安装Apache到d:\会形成目录d:\Apache2 4、 安装tomcat到d:\Tomcat4; 三、 具体配置 注:先把各服务停止以后才能开始配置,我的web应用目录为d:\webapp 配置步骤简述:先将tomcat和apache整合,然后配置tomcat连接池,最后用jsp界面测试
1) 在Tomcat4安装目录的conf目录下,新建一个目录jk,里面有两个文件,文件内容如下,可以根据自己实际安装的目录修改: a、 mod_jk.conf # # The following line instructs Apache to load the jk module # LoadModule jk_module modules/mod_jk-2.0.43.dll JkWorkersFile "d:/Tomcat4/conf/jk/workers.properties" JkLogFile "d:/Tomcat4/logs/mod_jk.log" # # Log level to be used by mod_jk # JkLogLevel error # # Root context mounts for Tomcat # JkMount /*.jsp ajp13 JkMount /servlet/* ajp13 ######################################################### # Auto configuration for the /query context starts. ######################################################### # # The following line makes apache aware of the location of the /annai context # 可能没有必要 Alias /elearning "d:/webapp" Options Indexes FollowSymLinks # # The following line mounts all JSP files and the /servlet/ uri to tomcat # JkMount /servlet/*.jsp ajp13 # # The following line prohibits users from directly accessing WEB-INF # #AllowOverride None #deny from all # # Use Directory too. On Windows, Location doesn't work unless case matches # #AllowOverride None #deny from all # # The following line prohibits users from directly accessing META-INF # #AllowOverride None #deny from all # # Use Directory too. On Windows, Location doesn't work unless case matches # #AllowOverride None #deny from all ####################################################### # Auto configuration for the /query context ends. ####################################################### b、 workers.properties # # workers.tomcat_home should point to the location where you # installed tomcat. This is where you have your conf, webapps and lib # directories. # workers.tomcat_home=D:\Tomcat4
# # workers.java_home should point to your Java installation. Normally # you should have a bin and lib directories beneath it. # workers.java_home=D:\j2sdk1.4.1 # # You should configure your environment slash... ps=\ on NT and / on UNIX # and maybe something different elsewhere. # ps=\ # ps=/ # #------ ADVANCED MODE ------------------------------------------------ # # #------ DEFAULT worket list ------------------------------------------ # # # The workers that your plugins should create and work with # worker.list=ajp13 # #------ DEFAULT ajp13 WORKER DEFINITION --------- # Defining a worker named ajp13 and of type ajp13 # Note that the name and the type do not have to match. # worker.ajp13.port=8009 worker.ajp13.host=localhost worker.ajp13.type=ajp13 # # Specifies the load balance factor when used with # a load balancing worker. # Note: # ----> lbfactor must be > 0 # ----> Low lbfactor means less work done by the worker. worker.ajp13.lbfactor=1 # Specify the size of the open connection cache. #worker.ajp13.cachesize # #------ DEFAULT LOAD BALANCER WORKER DEFINITION # # The loadbalancer (type lb) workers perform wighted round-robin # load balancing with sticky sessions. # Note: # ----> If a worker dies, the load balancer will check its state # once in a while. Until then all work is redirected to peer # workers. worker.loadbalancer.type=lb worker.loadbalancer.balanced_workers=ajp13
2) 把文件mod_jk-2.0.43.dll拷贝到Apache安装目录的moudles目录下; 3) 修改Apache安装目录下conf目录下的httpd.conf: 找到DocumentRoot 后面改为d:\webapp 找到DirectoryIndex 后面改为index.html index.htm index.jsp 在httpd.conf后面加上Include "d:\Tomcat4\conf\jk\mod_jk.conf"; 以下为配置连接池: 4) 在tomcat安装目录的conf目录下有server.xml,在server.xml的</Host>的前面加入如下代码: <Context path="" docBase="d:\\webapp\\" debug="0" reloadable="true" crossContext="true"> <Environment name="maxExemptions" type="java.lang.Integer" value="15"/> <Parameter name="context.param.name" value="context.param.value" override="false"/>
<Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/mydb"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>10000</value> </parameter> <parameter> <name>username</name> <value>sa</value> </parameter> <parameter> <name>password</name> <value>sa</value> </parameter> <parameter> <name>driverClassName</name> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </parameter> <parameter> <name>url</name> <value>jdbc:microsoft:sqlserver://server:1433;DatabaseName=test</value> </parameter> </ResourceParams> </Context> 5) 在web应用目录下有一个WEB-INF目录,配置此目录中的web.xml, 加入如下代码(这部分可能不用,也可以启用连接池): <web-app> <display-name>webapp</display-name> <resource-ref> <res-ref-name>jdbc/mydb</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> 6) 将jbuilder所使用的jdk改成jdk1.4.1(目录选择jdk1.4.1的安装目录); 7) 将sqlserver的jdbc驱动拷贝到tomcat安装目录的common\lib目录下。 四、 测试代码 注:不能在jbuilder中测试,因为jbuilder自己形成server8080.xml不含连接池配置,role是我数据库中的表。 <%@page language="java" import="java.sql.*,javax.naming.*,javax.sql.DataSource" %> <% DataSource ds = null; try { System.out.println("test"); Context env = (Context)new InitialContext().lookup("java:comp/env"); ds = (DataSource) env.lookup("jdbc/mydb"); } catch (NamingException ex) { ex.printStackTrace(); }
Connection con=null; con = ds.getConnection(); System.out.println("success:"+con.toString()); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select role_id,level_,description from role"); while(rs.next()){ System.out.println("role_id:"+rs.getInt("role_id")); System.out.println("description:"+rs.getString("description")); } rs.close(); rs = null; stmt.close(); stmt = null;
//return con; %> 注:建议不要把tomcat的服务在win2000里面自启动,而是手工启动,这样可以在tomcat启动后的消息窗口上看到打印出的结果。
最后、希望各位网友给予批评指正!
|

|
|
相关文章:相关软件: |
|