首 页 教育新闻课件中心论文中心教学教案试题中心语文专题综合下载技术教程公务员  
设为首页
加入收藏
联系我们
您当前的位置:中国教育资源网 -> 技术教程 -> 网络相关 -> 服务器 -> Web服务器 -> 技术内容 退出登录 用户管理

tomcat5.0+mysql配置JDBCRealm,DBCP,ssl,及中文乱码解决详解Web服务器教程

论文作者:佚名  论文来源:不详  论文发布时间:2006-6-18 21:23:50  论文发布人:chjchjchj

减小字体 增大字体

准备环境:
1.j2sdk-1_4_2-windows-i586.exe //jdk
2.mysql-4.0.20d-win.zip //mysql数据库
3.mysqlcc-0.9.4-win32.zip //mysqlGUI控制
4.jakarta-tomcat-5.0.27.exe //tomcat服务器
5.mysql-connector-java-3.0.14-production.zip //内含mysql驱动

安装步骤:
1.安装jdk
2.安装tomcat
3.安装mysql
4.安装mysqlcc
5.将驱动包解压,拷贝mysql-connector-java-3.0.14-production-bin.jar到tomcat/common/lib下
或者下载mm.mysql-2.0.14-you-must-unjar-me.jar,解压后拷贝其中的mm.mysql-2.0.14-bin.jar

Tomcat5.0配置 本例使用安装密码 198277
1.配置manager 管理应用程序
在conf/server.xml 中
添加如下

<Service name="Catalina">
...

<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/kinetic/tomcat5/server/webapps/manager">
</Context>

</Service>

限制ip访问配置
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/kinetic/tomcat5/server/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127.0.0.1"/>
</Context>
测试为:http://localhost:8080/manager/html

2.配置JDBCRealm容器管理安全,以mysql-4.0数据库为例
a.拷贝驱动mm.mysql-2.0.14-bin.jar到common/lib/下
b.在数据库ycg中建表

create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);

create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);

c.修改server.xml如下(默认数据库为root,无密码,如果有形如:connectionURL="jdbc:mysql://localhost/authority?

user=dbuser&password=dbpass")
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/ycg?user=root"
connectionName="" connectionPassword=""
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />

d.在数据库中添加入tomcat的默认配置数据:

+-----------+-----------+
user_name role_name
+-----------+-----------+
admin admin
admin manager
both role1
both tomcat
role1 role1
tomcat tomcat
+-----------+-----------+
+-----------+-----------+
user_name user_pass
+-----------+-----------+
tomcat tomcat
both tomcat
role1 tomcat
admin 198277
+-----------+-----------+

e.启动mysql,启动tomcat,此后tomcat将从数据库中读用户规则认证.默认的conf/tomcat-users.xml失效

3.DBCP的配置
a.设置
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>

可使失效的数据连接重新启用.
配套设置

<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
失效时间
如果要写入日志
设置
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
以上三个默认都是false
b.以mysql为例,配置数据连接池
c.配置新的用户与数据库,必须设定密码,空密码将导致连接失败
e.
指定root密码:mysqladmin -u root -h localhost password "198277"
(需修改上面的jdbcrealm设置connectionURL="jdbc:mysql://localhost/ycg?user=root&password=198277")
命令mysql进入匿名连接到服务器
密码访问
shell> mysql -h host -u user -p
Enter password: ********

//如果root没有密码,以下是不成功的.(试过了)
mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost
-> IDENTIFIED BY 'javadude' WITH GRANT OPTION;
mysql> create database javatest;
mysql> use javatest;
mysql> create table testdata (
-> id int not null auto_increment primary key,
-> foo varchar(25),
-> bar int);

在conf/server.xml中<host></host>中添加
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>

<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>

<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<!-- MySQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>javauser</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>

<!-- Class name for the old mm.mysql JDBC driver - uncomment this entry and comment next
if you want to use this driver - we recommend using Connector/J though
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
-->

<!-- Class name for the official MySQL Connector/J driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parame
[] [返回上一页] [打 印] [收 藏]  
 ∷相关技术评论  (评论内容只代表网友观点,与本站立场无关!) [查看发表评论...]
 
 中国教育资源网免费技术教程下载中心-站内广告 站内广告 中国教育资源网免费技术教程下载中心-站内广告 
 中国教育资源网站内搜索 站内搜索 中国教育资源网站内搜索 
 

   
 中国教育资源网免费技术教程下载中心-栏目导航 栏目导航 中国教育资源网免费技术教程下载中心-栏目导航 
· Windows 9XMEXP · Windows NT20002003
· LinuxBSD · 系统综合
· IISApache · 硬件技术
· Web服务器 · FTP服务器
· 邮件服务器 · 域名服务器
· Windows服务器 · 代理服务器
· 服务器综合
 
中国教育资源网免费技术教程下载中心-相关教程  相关技术 中国教育资源网免费技术教程下载中心-相关教程
· Tomcat配置技巧Top
· Apache+Tomcat实现W
· Apache+Tomcat实现W
· Apache+Tomcat实现W
· Tomcat5中文问题解决
· [图文] 从Tomcat中得到更多
· RedHat 9.0+Apache+
· [图文] redhat自带apache2.
· Apache1.3.22与Tomc
· [图文] WINXP+APACHE+MYSQL
 中国教育资源网免费技术教程下载中心-本月热门教程 本月热门 中国教育资源网免费技术教程下载中心-本月热门教程 
 
 中国教育资源网免费技术教程下载中心-本日热门论文 本日热门 中国教育资源网免费技术教程下载中心-本日热门论文 
 
关于本站 - 网站帮助 - 免费课件 - 美容 - 绿色软件 - 软件下载 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 网站留言
浙ICP备06010405号 Email:cnkjz@163.com 技术支持:名流设计
版权所有 Copyright© 2002-2004 名流