Tomcat5.0 + mysql configuration JDBCREALM, DBCP, SSL, and Chinese garbled solving detailed

xiaoxiao2021-03-06  78

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 ... Limiting IP Access Configuration 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 true Make the failure data Connection Re-enable. Support Set removeabandONEDTimeout 60 Fair time If you want to write to log setting logabandoned true 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 in conf / server.xml reloadable = "true" crossContext = "true"> factory org.apache.commons. DBCP.BasicDataSourceFactory maxactive 100 maxidle 30

< Parameter> maxwait 10000 username javauser password javadude driverclassname org.gjt.mm.mysql.driver -> driverclassname com.mysql.jdbc.driver <-! 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 jdbc: mysql: // localhost: 3306 / javatest? AutoreConnect = true

removeabandoned True removeabandONEDTimeout 60 logabandoned true f. Call in the web service. Configure web.xml as: mysql test app DB Connection < / Description> jdbc / testdb javax.sql.datasource Container < / resource-ref> 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> </ head> <body> <h2> Results </ h2> <c: foreach var = "row" items = "$ r r.ROWS}"> foo $ {row.foo} Bar $ {row.bar} </ c: foreach> <</p> <p>/ 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 <Tomcat> 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 <! - <Connector Port = "8443" Maxthreads = "25" MaxSparethreads = "75" enablelookups = "55", "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: <! - define a ssl coyote http / 1.1 Connector on Port 8443 -> <connection port =" 8443 "maxthreads =" 150 "</p> <p>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> </ web-app> Add <security-constraint> <web-resource-collection> <web-resource-name> Success </ web-resource-name> <url-pattern> / </ url-pattern> <http- Method> get </ http-method> <http-method> post </ http-method> </ web-resource-collection> <user-data-constraint> <transport-guarance> confidential </ transport-guarance> </ User-data-constraint> </ security-constraint> f. Used as an example is to modify web.xml as <web-app Xmlns = "http://java.sun.com/xml/ns/j2ee" XMLns: XSI = "http://www.w3.org/2001/xmlschema-instance" xsi: schemAlocation = "http://java.sun.com/xml/ns/j2eehtp://java.sun.com/xml/ NS / J2EE / Web-App_2_4.xsd "Version =" 2.4 "> <Description> MySQL Test App </ Description> <secu Rity-constraint> <web-resource-collection> "Web-resource-name> Success </ web-resource-name> <url-pattern> / </ url-pattern> <http-method> get </ http-method > <http-method> post </ http-method> </ web-resource-collection> <user-data-connection> <transport-guarance> confidential </ transport-guarance> </ user-data-connectiont> </ Security-constraint> <</p> <p>Resource-Ref> <Description> DB Connection </ description> <res-ref-name> JDBC / TESTDB </ RES-REF-NAME> <res-type> javax.sql.datasource </ res-type> <RES- Auth> 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 <auth-connection-name> Web-user </ role-name> < / auth-constraint> <login-config> <auth-method> Basic </ auth-method> <realm-name> My Me MEMBER AREA </ realm-name> </ login-config> Modified web.xml <web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: schemAlocation = "http : //java.sun.com/xml/ns/j2eehttp: //java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "Version =" 2.4 "> <Description> MySQL Test App </ description > <security-constraint> <web-resource-collection> <web-resource-name> Success </ web-resource-name> <url-pattern> / </ url-pattern> <http-method> get </ http -method> <http-method> Post </ http-method> </ web-resource-collection> <auth-constraint> <role-name> web-user </ role-name> </ author-constraint> <user-data-constraint> <transport- Guarantee> confidential </ transport-guarance> </ user-data-constraint> </ security-constraint> <login-config> <auth-method> Basic </ auth-method> <realm-name> My MEMBER AREA </ Realm-name> </ login-config> <resource-ref> <description> DB Connection <</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-122869.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="122869" 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.040</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 = 'i3r62E_2FT7rL6376rmog3QyA3QguVxkZisce0ZSz5EuITMZQnJk4sNoQ48qhosOj02DuZdpNyStHEJZQwE3UXjQ_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>