Tomcat5.0 + mysql configuration JDBCREALM, DBCP, SSL resolve detailed

xiaoxiao2021-03-06  105

Preparation environment:

1.J2SDK-1_4_2-windows-i586.exe // jdk

2.Mysql-4.0.20d-win.zip // mysql database

3.Mysqlcc-0.9.4-win32.zip // mysqlgui control

4.Jakarta-Tomcat-5.0.27.exe // Tomcat server

5.Mysql-connector-java-3.0.14-Production.zip // Contains MYSQL driver

installation steps:

Install JDK

2. Install Tomcat

3. Install MySQL

4. Install mysqlcc

5. Packets will be driven, copy mysql-connector-java-3.0.14-production-bin.jar to tomcat / common / lib

Or download mm.mysql-2.0.14-you-must-unjar-me.jar, copy the mm.mysql-2.0.14-bin.jar after decompression

Tomcat5.0 configuration This example uses the installation password 198277

1. Configure the Manager management application

In Conf / Server.xml

Add as follows

...

DocBase = "/ usr / local / kinetic / tomcat5 / server / webapps / manager">

Restrict IP access configuration

DocBase = "/ usr / local / kinetic / tomcat5 / server / webapps / manager">

Allow = "127.0.0.1" />

Test is: http: // localhost: 8080 / manager / html

2. Configure the JDBCREALM container management security, take the mysql-4.0 database as an example.

a. Copy drive mm.mysql-2.0.14-bin.jar to Common / LIB /

b. Construction table in database 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. Modify Server.xml as follows (the default database is root, no password, if tangible, if: connectionURL = "JDBC: mysql: // localhost / authority?

User = dbuser & password = dbpass ")

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. Add the default configuration data of Tomcat in the database:

---------

---------

| 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. Start MySQL, start Tomcat, then Tomcat will read the user rule authentication from the database. Default conf / Tomcat-users.xml failure

3.DBCP configuration

a. set

removeabandoned

True

Re-enable the data connection of the failure.

Setup

removeabandonedTimeout

60

Failure time

If you want to write a log

Set

logabandoned

True

The above three defaults are False

b. Take MySQL as an example, configure data connection pool

c. Configure new users and databases, must set passwords, empty password will result in connection failure

e.

Specify root password: mysqladmin -u root -h localhost password "198277"

(You need to modify the above JDBCREALM settings ConnectionURL = "JDBC: mysql: // localhost / ycg? User = root & password = 198277")

Command mysql enters anonymous connection to the server

Password access

Shell> mysql -h host -u user -p

ENTER password: ********

// If root has no password, the following is unsuccessful. (Tried)

Mysql> grant all privileges on *. * to javauser @ localhost-> identified by 'javadude' with grant option;

Mysql> Create Database Javates

Mysql> Use javatest;

Mysql> Create Table TestData

-> ID INT NOT NULL AUTO_INCREMENT Primary Key,

-> foo varchar (25),

-> bar int);

Add in in Conf / Server.xml

Debug = "5" reloadable = "true" crossContext = "true">

prefix = "localhost_dbtest_log." suffix = ". txt"

TimeStamp = "true" />

Auth = "container"

TYPE = "javax.sql.datasource" />

factory

org.apache.commons.dbcp.basicDataSourceFactory

Configure your mysqld max_connections large enough to handle

All of Your DB Connections. Set to 0 for no limit.

->

maxactive

100

Set to 0 for no limit.

->

maxidle

30

IN ms, in this example 10 seconds. An Exception Is Thrown IF

THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely.

->

maxWait 10000

Username

javauser

Password

javadude

If you want to use tris driver - We Recommend Using Connector / J Though

driverclassname

Org.gjt.mm.mysql.driver

->

driverclassname

com.mysql.jdbc.driver

The autoreconnect = true argument to the url makess sure what

MM.MYSQL JDBC Driver Will Automatically Reconnect IF MySQLD CLOSED THE

.

->

URL

jdbc: mysql: // localhost: 3306 / javatest? AutoreConnect = true

removeabandoned

True

removeabandonedTimeout

60

logabandoned

True

f. Call in the web service. Configure web.xml such as:

XSI: SchemAlocation = "http://java.sun.com/xml/ns/j2ee

Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "

Version = "2.4">

MySQL Test App

DB Connection

JDBC / TESTDB

javax.sql.datasource

container

g. Test Test.jsp

<% @ Taglib Uri = "http://java.sun.com/jsp/jstl/sql" prefix = "SQL"%>

<% @ Taglib Uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%>

Select ID, Foo, Bar from testdata

DB Test </ Title></p> <p></ hEAD></p> <p><body></p> <p><H2> Results </ h2></p> <p><c: foreach var = "row" items = "$ r rROWS}"></p> <p>Foo $ {row.foo}</p> <p>Bar $ {row.bar}</p> <p></ c: foreach></p> <p></ body></p> <p></ html></p> <p>h. New web application</p> <p>Download Jakarta-Taglibs-Standard-1.1.0</p> <p>Copy JSTL.JAR AND STANDARD.JAR TO YOUR Web App's Web-INF / LIB</p> <p>DBTEST /</p> <p>WEB-INF /</p> <p>Web.xml</p> <p>LIB /</p> <p>JSTL.jar</p> <p>Standard.jar</p> <p>Test.jsp</p> <p>Copy to WebApps /</p> <p>i. Launch MySQL, Tomcat</p> <p>access:</p> <p>Http: // localhost: 8080 / dbtest / test.jsp</p> <p>display:</p> <p>RESULTS</p> <p>Foo Hello</p> <p>Bar 12345</p> <p>4.SL configuration, take JDK1.4.2 as an example</p> <p>a. Enter% java_home% / bin</p> <p>Run command: keytool -genkey -alias tomcat -keyalg rsa</p> <p>Install the password with Tomcat to 198277, Ketool Set the password to 198277 as an example</p> <p>Enter keystore password: 198277</p> <p>What is your name and last name?</p> <p>[Unknown]: YCG</p> <p>What is your organizational unit name? [Unknown]: NJU</p> <p>What is your organization name?</p> <p>[Unknown]: NJU</p> <p>What is your city or region name?</p> <p>[Unknown]: nanjing</p> <p>What is your state or provincial name?</p> <p>[Unknown]: jiangsu</p> <p>What is the two-letter country code in this unit?</p> <p>[Unknown]: ND</p> <p>CN = ycg, ou = nju, o = nju, l = nanjing, st = jiangsu, c = ND correct?</p> <p>[No]: Y</p> <p>Enter <Tomcat> master password</p> <p>(If you pass the same password with the KeyStore, press Enter.): 198277</p> <p>b. You can find the .KeyStore file in your D: / Documents and Settings / Current User Directory. Copy it to the CONF / folder.</p> <p>c. Found in server.xml</p> <p><! -</p> <p><Connector Port = "8443"</p> <p>Maxthreads = "150" MINSPARETHREADS = "25" maxsparethreads = "75"</p> <p>Enablelookups = "false" disableuploadtimeout = "true"</p> <p>Acceptcount = "100" debug = "0" scheme = "https" secure = "true"</p> <p>ClientAuth = "false" sslprotocol = "tls" /></p> <p>-></p> <p>Remove the comment</p> <p>Add Configuration Field: KeyStorefile = "/ conf / .keystore" KeyStorePass = "198277"</p> <p>Such as: <! - Define a SSL Coyote Http / 1.1 Connector On Port 8443 -></p> <p><Connector Port = "8443"</p> <p>Maxthreads = "150" MINSPARETHREADS = "25" maxsparethreads = "75"</p> <p>Enablelookups = "false" disableuploadtimeout = "true"</p> <p>Acceptcount = "100" debug = "0" scheme = "https" secure = "true"</p> <p>ClientAuth = "false" sslprotocol = "tls" keystorefile = "/ conf / .keystore"</p> <p>KeyStorePass = "198277" /></p> <p>d. Test is:</p> <p>Https: // localhost: 8443</p> <p>e. Adding an SSL authentication in your own program is:</p> <p>Add <web-app> </ web-app> in Web.xml</p> <p><Security-constraint></p> <p><Web-Resource-Collection></p> <p><Web-Resource-Name> Success </ Web-Resource-Name></p> <p><url-pattern> / </ url-pattern></p> <p><http-method> get </ http-method></p> <p><http-method> pos </ http-method></p> <p></ Web-Resource-Collection></p> <p><user-data-connectiont></p> <p><Transport-Guarance> Confidential </ Transport-Guarance></p> <p></ user-data-connectiont></p> <p></ security-connectiont></p> <p>f. Used as an example</p> <p>Modify Web.xml</p> <p><web-app xmlns = "http://java.sun.com/xml/ns/j2ee"</p> <p>XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance"</p> <p>XSI: SchemAlocation = "http://java.sun.com/xml/ns/j2ee</p> <p>Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "</p> <p>Version = "2.4"></p> <p><Description> MySQL Test App </ description></p> <p><Security-constraint></p> <p><Web-Resource-Collection></p> <p><Web-Resource-Name> Success </ Web-Resource-Name></p> <p><url-pattern> / </ url-pattern></p> <p><http-method> get </ http-method></p> <p><http-method> pos </ http-method></p> <p></ Web-Resource-Collection></p> <p><user-data-connectiont></p> <p><Transport-Guarance> Confidential </ Transport-Guarance></p> <p></ user-data-connectiont></p> <p></ security-connectiont></p> <p><resource-ref></p> <p><Description> DB Connection </ Description></p> <p><res-ref-name> JDBC / TESTDB </ RES-REF-NAME></p> <p><Res-Type> javax.sql.datasource </ res-Type></p> <p><res-auth> container </ res-auth></p> <p></ resource-ref></p> <p></ web-app></p> <p>access:</p> <p>Https: // localhost: 8443 / dbtest / test.jsp</p> <p>g. If you are combined with 2 configured JDBCREALM, form authentication</p> <p>Add user_name: ycg role_name first in the user_roles table</p> <p>EB-User</p> <p>Add user_name: ycg user_pass: 198277</p> <p>Then add it in Web.xml</p> <p><auth-constraint></p> <p><role-name> Web-user </ role-name></p> <p></ auth-constraint></p> <p><login-config></p> <p><auth-method> Basic </ auth-method></p> <p><realm-name> My Member Area </ realm-name> </ login-config></p> <p>Modified Web.xml, such as:</p> <p><web-app xmlns = "http://java.sun.com/xml/ns/j2ee"</p> <p>XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance"</p> <p>XSI: SchemAlocation = "http://java.sun.com/xml/ns/j2ee</p> <p>Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "</p> <p>Version = "2.4"></p> <p><Description> MySQL Test App </ description></p> <p><Security-constraint></p> <p><Web-Resource-Collection></p> <p><Web-Resource-Name> Success </ Web-Resource-Name></p> <p><url-pattern> / </ url-pattern></p> <p><http-method> get </ http-method></p> <p><http-method> pos </ http-method></p> <p></ Web-Resource-Collection></p> <p><auth-constraint></p> <p><role-name> Web-user </ role-name></p> <p></ auth-constraint></p> <p><user-data-connectiont></p> <p><Transport-Guarance> Confidential </ Transport-Guarance></p> <p></ user-data-connectiont></p> <p></ security-connectiont></p> <p><login-config></p> <p><auth-method> Basic </ auth-method></p> <p><realm-name> My Member Area </ realm-name></p> <p></ login-config></p> <p><resource-ref></p> <p><Description> DB Connection </ Description></p> <p><res-ref-name> JDBC / TESTDB </ RES-REF-NAME></p> <p><Res-Type> javax.sql.datasource </ res-Type></p> <p><res-auth> container </ res-auth></p> <p></ resource-ref></p> <p></ web-app></p> <p>test:</p> <p>Http: // localhost: 8080 / dbtest / test.jsp</p> <p>Will connect to the SSL and form authentication. User password can be added in user_roles, and Users.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-97002.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="97002" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.045</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'mQ_2FRJniXtO8u6bscYiyaE0Xdcs0Qy8PEzKmg3dhHf3AtbH7zYYaD1aRsZuxR_2Fwl0Na9W6_2BQmqIWXvIspdIjqQg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>