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"> Context> Service> Restrict IP access configuration DocBase = "/ usr / local / kinetic / tomcat5 / server / webapps / manager"> Allow = "127.0.0.1" /> Context> 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 parameter> Re-enable the data connection of the failure. Setup parameter> Failure time If you want to write a log Set parameter> 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 Debug = "5" reloadable = "true" crossContext = "true"> prefix = "localhost_dbtest_log." suffix = ". txt" TimeStamp = "true" /> Auth = "container" TYPE = "javax.sql.datasource" /> parameter>
Configure your mysqld max_connections large enough to handle All of Your DB Connections. Set to 0 for no limit. -> parameter>
Set to 0 for no limit. -> parameter>
IN ms, in this example 10 seconds. An Exception Is Thrown IF THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely. -> parameter> parameter> parameter>
If you want to use tris driver - We Recommend Using Connector / J Though parameter> -> parameter>
The autoreconnect = true argument to the url makess sure what MM.MYSQL JDBC Driver Will Automatically Reconnect IF MySQLD CLOSED THE . -> parameter> parameter> parameter> parameter> Resourceparams> Context> 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"> resource-ref> web-app> 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 SQL: Query> hEAD> Foo $ {row.foo} Bar $ {row.bar} c: foreach> body> html> h. New web application Download Jakarta-Taglibs-Standard-1.1.0 Copy JSTL.JAR AND STANDARD.JAR TO YOUR Web App's Web-INF / LIB DBTEST / WEB-INF / Web.xml LIB / JSTL.jar Standard.jar Test.jsp Copy to WebApps / i. Launch MySQL, Tomcat access: Http: // localhost: 8080 / dbtest / test.jsp display: RESULTS Foo Hello Bar 12345 4.SL configuration, take JDK1.4.2 as an example a. Enter% java_home% / bin Run command: keytool -genkey -alias tomcat -keyalg rsa Install the password with Tomcat to 198277, Ketool Set the password to 198277 as an example Enter keystore password: 198277 What is your name and last name? [Unknown]: YCG What is your organizational unit name? [Unknown]: NJU What is your organization name? [Unknown]: NJU What is your city or region name? [Unknown]: nanjing What is your state or provincial name? [Unknown]: jiangsu What is the two-letter country code in this unit? [Unknown]: ND CN = ycg, ou = nju, o = nju, l = nanjing, st = jiangsu, c = ND correct? [No]: Y Enter (If you pass the same password with the KeyStore, press Enter.): 198277 b. You can find the .KeyStore file in your D: / Documents and Settings / Current User Directory. Copy it to the CONF / folder. c. Found in server.xml
Maxthreads = "150" MINSPARETHREADS = "25" maxsparethreads = "75" Enablelookups = "false" disableuploadtimeout = "true" Acceptcount = "100" debug = "0" scheme = "https" secure = "true" ClientAuth = "false" sslprotocol = "tls" /> -> Remove the comment Add Configuration Field: KeyStorefile = "/ conf / .keystore" KeyStorePass = "198277" Such as: Maxthreads = "150" MINSPARETHREADS = "25" maxsparethreads = "75" Enablelookups = "false" disableuploadtimeout = "true" Acceptcount = "100" debug = "0" scheme = "https" secure = "true" ClientAuth = "false" sslprotocol = "tls" keystorefile = "/ conf / .keystore" KeyStorePass = "198277" /> d. Test is: Https: // localhost: 8443 e. Adding an SSL authentication in your own program is: Add Web-Resource-Collection> user-data-connectiont> security-connectiont> f. Used as an example Modify Web.xml XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance" XSI: SchemAlocation = "http://java.sun.com/xml/ns/j2ee Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd " Version = "2.4"> Web-Resource-Collection> user-data-connectiont> security-connectiont> resource-ref> web-app> access: Https: // localhost: 8443 / dbtest / test.jsp g. If you are combined with 2 configured JDBCREALM, form authentication Add user_name: ycg role_name first in the user_roles table EB-User Add user_name: ycg user_pass: 198277 Then add it in Web.xml auth-constraint> Modified Web.xml, such as: XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance" XSI: SchemAlocation = "http://java.sun.com/xml/ns/j2ee Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd " Version = "2.4"> Web-Resource-Collection> auth-constraint> user-data-connectiont> security-connectiont> login-config> resource-ref> web-app> test: Http: // localhost: 8080 / dbtest / test.jsp Will connect to the SSL and form authentication. User password can be added in user_roles, and Users. Results h2>