设为首页 收藏本站
查看: 897|回复: 0

[经验分享] Tomcat Web Server Administration Tool + 连接池连接问题

[复制链接]

尚未签到

发表于 2016-11-11 07:50:18 | 显示全部楼层 |阅读模式
附 apache-tomcat-5.5.28-admin.zip  下载
 
 
Tomcat 5.5实用工具Tomcat Web Server Administration Tool运行于Web环境,通过浏览器可以非常方便地进行Tomcat服务器的配置,如图所示:
 
  DSC0000.jpg
 
但是,Tomcat 5.5 以后的binary Core安装版不再提供Tomcat Web Server Administration Tool,如若要使用该实用工具,必须从http://tomcat.apache.org/下载Administration Web Application压缩包,且需要在本地进行配置。
 
  DSC0001.jpg
 
一、下载文件apache-tomcat-5.5.27-admin.zip
 
 
  DSC0002.jpg
 
二、将文件apache-tomcat-5.5.27-admin.zip解压到目录F:\Tomcat\apache-tomcat-5.5.27
apache-tomcat-5.5.27目录内容为:
 
DSC0003.jpg
 
 
到此,实用工具Tomcat Web Server Administration Tool的应用程序Administration Web Application只是存在本地,还没有被发布到Tomcat服务器中,所以通过访问http://localhost:8080/admin得到的结果如下:
Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it.
 
现在开始Tomcat中配置Administration Web Application
 
三、将文件apache-tomcat-5.5.27\conf\Catalina\localhost\ admin.xml拷贝到Tomcat服务器所在安装目录E:\j2ee\Tomcat 5.5\conf\Catalina\localhost目录。
admin.xml具体内容:
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!--
    Context configuration file for the Tomcat Administration Web App
    $Id: admin.xml 565211 2007-08-13 00:09:38Z markt $
-->
<Context docBase="${catalina.home}/server/webapps/admin" privileged="true"
         antiResourceLocking="false" antiJARLocking="false">
  <!-- Uncomment this Valve to limit access to the Admin app to localhost
   for obvious security reasons. Allow may be a comma-separated list of
   hosts (or even regular expressions).
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="127.0.0.1"/>
  -->
</Context>
 
四、将apache-tomcat-5.5.27\server\webapps目录下的admin目录整个拷贝到Tomcat服务器所在安装目录E:\j2ee\Tomcat 5.5\server\webapps目录。
 
五、编辑文件E:\j2ee\Tomcat 5.5\conf\ tomcat-users.xml,为该实用工具程序添加用户zhans信息。
tomcat-users.xml具体内容:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="admin" password="admin" roles="admin,manager"/>
<user username="zhans" password="nice" roles="admin,manager"/>
</tomcat-users>
注意:username/password任意组合,但roles=admin”角色不可随意改动!
 
六、重启Tomcat服务器,访问URL : http://localhost:8080/admin,验证通过后,即可使用实用工具Tomcat Web Server Administration Tool
  DSC0004.jpg
 
 
 
 
 
 
 
 
 
 
 
 
 
----------------------------------------使用TOMCAT5.5连接池连接mysql(解决Cannot create JDBC driver of class '' for connect URL
 
1 建立Context:   在Tomcat中新建一个Context,让其docBase指向程序所在目录(若您下载的是war文件,则指向该文件目录StrutsArticle)。
在tomcat\conf\Catalina\localhost目录下建立一个xml文件,名称为你所发布的web应用的名称.xml,(如StrutsArticle.xml)打开添加内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
      name="jdbc/StrutsArticle"
      type="javax.sql.DataSource"
      password="123456"
      driverClassName="org.gjt.mm.mysql.Driver"
      maxIdle="2"
      maxWait="50"
      username="root"
      url="jdbc:mysql://localhost:3306/strutsarticle"
      maxActive="4"/>
</Context>


2 建立Data Source: 
进入http://localhost:81/admin,选择Resources-Data sources进入配置数据源界面,选择
Data Source Actions ->选择Create New Data Source,进入配置详细信息界面
 
JNDI Name: ->jdbc/StrutsArticle
Data Source URL ->jdbc:mysql://localhost:3306/strutsarticle
JDBC Driver Class-> org.gjt.mm.mysql.Driver
 
 
 
 
DBConnection.java
 
package com.tiandinet.StrutsArticle.Utils;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;

public class DBConnection {
    public static synchronized Connection getConnection() throws Exception {
        try {
            Context initCtx = new javax.naming.InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            DataSource ds = (DataSource) envCtx.lookup("jdbc/StrutsArticle");
            return ds.getConnection();
        } catch (Exception e) {
            throw e;
        }
    }
}
 
 
 
 
 
 
 
 
-------------------------------- 以下是参考资料
 
  1)启动Tomcat服务器,打开浏览器,输入http://localhost:8080/admin(其中localhost是名称服务器或称为主机),
进入管理界面的登陆页面,这时候请输入原来安装时要求输入的用户名和密码,登陆到管理界面,
  2)选择Resources-Data sources进入配置数据源界面,选择
Data Source Actions ->选择Create New Data Source,进入配置详细信息界面
主要内容例如下:
JNDI Name: ->jdbc/mysql
Data Source URL ->jdbc:mysql://localhost:3306/test
JDBC Driver Class-> org.gjt.mm.mysql.Driver

3)修改\conf\Catalina\localhost目录下建立一个xml文件,名称为你所发布的web应用的名称.xml,(如testpool.xml)打开添加内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
       name="jdbc/mysql"
       type="javax.sql.DataSource"
       password="123456"
       driverClassName="org.gjt.mm.mysql.Driver"
       maxIdle="2"
       maxWait="50"
       username="root"
       url="jdbc:mysql://localhost:3306/test"
       maxActive="4"/>

  </Context>
  
内容同conf/server.xml中<GlobalNamingResources>
<Resource
       name="jdbc/mysql"
       type="javax.sql.DataSource"
       password="123456"
       driverClassName="org.gjt.mm.mysql.Driver"
       maxIdle="2"
       maxWait="50"
       username="root"
       url="jdbc:mysql://localhost:3306/test"
       maxActive="4"/>
</GlobalNamingResources>

少了这一步会报错:Cannot create JDBC driver of class '' for connect URL 'null'
4)修改web.xml
  打开%TOMCAT_HOME%\conf\web.xml或yourwebapp/web-inf/web.xml,添加以下内容:
     <resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/mysql</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
     </resource-ref>

     注意res-ref-name填写的内容要与在上文提到的JNDI Name名称一致。
到这里,配置工作就基本完成了!
  5)引用JNDI时用"java:comp/env/jdbc/mysql";
建立文件测试 test.jsp:
<%@pagecontentType="text/html;charset=utf-8" %>
<%@pageimport="java.sql.*" %>
<%@pageimport="javax.sql.*" %>
<%@pageimport="javax.naming.*" %>
<html>
<head>
<title>Tomcat连接池测试</title>
</head>
<body>
<%
Context ctx=new InitialContext();
Connection conn=null;
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
conn=ds.getConnection();
Statement stmt=conn.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select * from testexample");
while(rs.next()){
out.println(rs.getInt(1));
out.println(rs.getString(2));
out.println(rs.getString(3));
}
out.println("数据库操作成功!");
rs.close();
stmt.close();
conn.close();
     
%>
</body>
</html>

 
 
 
 
 
 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-298616-1-1.html 上篇帖子: sql 字符串汇总 下篇帖子: 数据库基本sql语句
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表