Preparation environment: 1.J2SDK-1_4_2-windows-i586.exe //jdk2.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: 1. Install JDK2. Install Tomcat3. Install MySQL4. Install mysqlcc5. 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, decompression The mm.mysql-2.0.14-bin.jartomcat5.0 Configuring this example Use the installation password 1982771. Configure the Manager management application Add the following ... context> service> Limiting IP Access Configuration context> Test is: http: // localhost: 8080 / manager / html2. Configure 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 / below B. Table Create Table Users in Database YCG (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 (role_name)); c. Modify Server.xml as follows (the default database is root, no password, if tangible: connectionURL = "JDBC: mysql: // LocalHost / Authority? User = dbuser & password = dbpass ") d. Add Tomcat's default configuration data to the database: --------- --------- | User_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 from the database User rule authentication. Default conf / tomcat-users.xml failed 3.DBCP configuration a. Setting removeabandONED name> true value> parameter> Make the failure data Connection Re-enable. Support Set removeabandONEDTimeout name> 60 value> parameter> Fair time If you want to write to log setting logabandoned name> true value> parameter > The above three defaults are falseb. Take MySQL as an example, configure the data connection pool c. Configure new users and databases, must set passwords, the empty password will result in the connection fail E. Specify root password: mysqladmin -u root -h Localhost Password "198277" (need to modify the JDBCREALM settings on the above "JDBC: mysql: // localhost / ycg? user = root & password =
198277 ") Command MySQL Enter anonymous Connection to Server Password Access Shell> MySQL -H Host -u User -penter 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 javatest; mysql> use javatest; mysql> create table testdata (-> id int not null auto_increment primary Key, -> foo varchar (25), -> bar int); Add host> in conf / server.xml reloadable = "true" crossContext = "true"> factory name> org.apache.commons. DBCP.BasicDataSourceFactory value> parameter> maxactive name> 100 value> parameter> maxidle name> 30 value>
parameter> < Parameter> maxwait name> 10000 value> parameter> username name> javauser value> parameter> password name> javadude value> parameter> driverclassname name> org.gjt.mm.mysql.driver value> parameter> -> driverclassname name> 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. -> URL name> jdbc: mysql: // localhost: 3306 / javatest? AutoreConnect = true value> parameter>
removeabandoned name> True value> parameter> removeabandONEDTimeout name> 60 value> parameter> logabandoned value> true value> parameter> resourceparams> context> f. Call in the web service. Configure web.xml as: mysql test app description> DB Connection < / Description> jdbc / testdb res-name> javax.sql.datasource res-type> Container res-auth> < / 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> DB Test Title> head> Results h2> foo $ {row.foo} Bar $ {row.bar} c: foreach> <
/ body> html> h. New web application download jakarta-taglibs-standard-1.1.0copy 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 / Next i. Start mysql, Tomcat Access: http:// localhost: 8080 / dbtest / test.jsp display: Results foo hello bar 123454.ssl configuration, JDK1.4.2 Take an example a. Enter% java_home% / bin Run command: keytool -genkey -alias tomcat -keyalg RSA is 198277 with Tomcat installation password, KETOOL Settings Password 198277 Tried a KeyStore Password: 198277 What is your name and last name? [Unknown]: YCG Your organizational unit name? [Unknown]: NJU Your organizational name is? [Unknown]: What is the NJU Your city or the area name? [Unknown]: What is the name of NANJING Your state or province? [Unknown]: What is the two-letter country code of this unit [UNKNOWN]: ndcn = ycg, ou = nju, o = nju, l = nanjing, st = jiangsu, c = nd correct? [No]: Y Enter The primary password (if the key is the same, press Enter): 198277B. In your d: / documents and settings / current user directory can be found. KeyStore file. Copy it Under the conf / folder .c. Find -> Remove the comment Add Configuration Field: KeyStorefile =" / conf / .keystore "KeyStorePass =" 198277 "such as:
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: 8443e. Add SSL authentication mode in our own program: in Web.xml web-app> Add Success web-resource-name> / url-pattern> get http-method> post http-method> web-resource-collection> confidential transport-guarance> User-data-constraint> security-constraint> f. Used as an example is to modify web.xml as MySQL Test App Description> "Web-resource-name> Success web-resource-name> / url-pattern> get http-method > post http-method> web-resource-collection> confidential transport-guarance> user-data-connectiont> Security-constraint> <
Resource-Ref> DB Connection description> JDBC / TESTDB RES-REF-NAME> javax.sql.datasource res-type> Container res-auth> resource-ref> web-app> Access: https: // localhost: 8443 / dbtest / test.jspg. If you combine with 2 configured JDBCREALM, formal authentication first Add user_name: Ycg role_name: web-user in the user_roles table Add user_name: Ycg user_pass: 198277 in the user_pass: 198277 and add Web-user role-name> < / auth-constraint> Basic auth-method> My Me MEMBER AREA realm-name> login-config> Modified web.xml MySQL Test App description > Success web-resource-name> / url-pattern> get http -method> Post http-method> web-resource-collection> web-user role-name> author-constraint> confidential transport-guarance> user-data-constraint> security-constraint> Basic auth-method> My MEMBER AREA Realm-name> login-config> DB Connection <