Tomcat configuration highlights

Source: Internet
Author: User

Modify APACHE-Tomcat-6.0.20 // conf // tomcat-users.xml file <br/> 1 .. add the Tomcat administrator username and password <br/> to modify the content of the <tomcat-users> tab on line 1, the modified content is as follows <br/> <tomcat-users> <br/> <role rolename = "admin"/> <br/> <role rolename = "manager "/> <br/> <User Username = "jadyer" Password = "22" roles = "Admin, manager "/> <br/> </tomcat-users>Modify APACHE-Tomcat-6.0.20 // conf // web. XML file <br/> 1 .. when the welcome file of the javaweb project is not set or does not exist, the available page is displayed as a list after the web application is accessed. <br/> set the value of the listings parameter in line 1, the modified content can be changed from false to true by default. <br/>, <br/> <servlet> <br/> <servlet-Name> default </servlet-Name> <br/> <servlet-class> Org. apache. catalina. servlets. defaultServlet </servlet-class> <br/> <init-param> <br/> <param-Name> debug </param-Name> <br/> <param-Value> 0 </param-value> <br/> </init-param> <br/> <param-Name> listings </Param -Name> <br/> <param-value> true </param-value> <br/> </init-param> <br/> <load-on-startup> 1 </load-on-startup> <br/> </servlet>Modify APACHE-Tomcat-6.0.20 // conf // server. XML file <br/> 1 .. change 67 rows <connector Port = "8080" protocol = "HTTP/1.1" connectiontimeout = "20000" redirectport = "8443"/> <br/> to <connector Port =" 8088 "protocol =" HTTP/1.1 "connectiontimeout =" 20000 "redirectport =" 8443 "maxthreads =" 88 "uriencoding =" UTF-8 "/> <br/> port --------- specify Tomcat default the port number used <br/> maxthreads --- specify the maximum number of connections that Tomcat can process simultaneously <br/> uriencoding -- solve the garbled problem when passing Chinese parameters using http get <br/> 2 .. map the project to tomcat6 // conf // server. add <context Path = "/test" docbase = "F: /workspace/test/webroot "reloadable =" true "/> <br/> then access http: // 127.0.0.1 directly in the browser: 8088/test <br/> but the corresponding jar package must exist in the test // webroot // WEB-INF // Lib. <br/> otherwise, an error may be reported, this is the ing path.Modify APACHE-Tomcat-6.0.20 // conf // context. XML file <br/> 1 .. modify the 19 rows of <context> to <context reloadable = "true"> <br/> to be a file or web in a Java Web application. after the XML file is modified, the Tomcat server automatically reloads the current javaweb application, avoid restarting Tomcat <br/> This modification may affect the running performance of Tomcat <br/> If Tomcat is used as the server in the product stage, it is best to change it to <context reloadable = "false"> <br/> 2 .. configure the Tomcat built-in connection pool <br/> most Java Web servers have built-in connection pools, which can be directly used through simple configuration, in addition, the performance is better and more reliable <br/> the default connection pool technology used in the Tomcat server is DBCP. The specific configuration is to modify the Apache-tomc At-6.0.20 // conf // context. XML file <br/> we only need. the following content is added to line 1 of XML <br/> <Resource Name = "JDBC/oracleds" <br/> auth = "Container" <br/> type = "javax. SQL. datasource "<br/> maxactive =" 100 "<br/> maxidle =" 30 "<br/> maxwait =" 10000 "<br/> driverclassname =" oracle. JDBC. oracledriver "<br/> username =" Scott "<br/> Password =" oracle "<br/> url =" JDBC: oracle: thin: @ 127.0.0.1: 1521: jadyer "/> <br/> <Resource Name =" JDBC/mysqlds "<br/> auth =" Container "<br/> type =" javax. SQL. datasource "<br/> maxactive =" 100 "<br/> maxidle =" 30 "<br/> maxwait =" 10000 "<br/> driverclassname =" com. mySQL. JDBC. driver "<br/> username =" root "<br/> Password =" root "<br/> url =" JDBC: mysql: // 127.0.0.1: 3306/jadyer? Characterencoding = UTF-8 "/> <br/> <Resource Name =" JDBC/sqlserver2000ds "<br/> auth =" Container "<br/> type =" javax. SQL. datasource "<br/> maxatcive =" 100 "<br/> maxidle =" 30 "<br/> maxwait =" 10000 "<br/> driverclassname =" com. microsoft. JDBC. sqlserver. sqlserverdriver "<br/> username =" sa "<br/> Password =" sa "<br/> url =" JDBC: Microsoft: sqlserver: // 127.0.0.1: 1433; databasename = jadyer "/> <br/> name ------------- data Source object name <br/> auth ------------- authentication method <br/> type ------------- type of the resource <br/> initialsize ------ the initial number of connections in the connection pool. That is, the number of connections initially established after the Tomcat server is started <br/> maxactive -------- the maximum number of connections that can be allocated at the same time in the connection pool. If the parameter value is not a positive value, it indicates no limit <br/> maxidle ---------- the maximum number of idle connections that can be retained in the connection pool. Idle connections larger than this quantity will be released. Negative number indicates no limit <br/> minidle ---------- the minimum number of idle connections that can be retained in the connection pool. If the number is smaller than this, more idle connections will be created. "0" indicates the maximum timeout value for a connection in the connection pool that is not created <br/> maxwait. The Unit is millisecond <br/> driverclassname -- database-driven class <br/> username --------- username of the database for which the connection pool is established <br/> password --------- password of the database for which the connection pool is established <br/> br/> URL -------------- parameter value of the URL required to create a database connection <br/> the context is modified. after XML, you also need to copy the Oracle and MySQL driver class libraries to Apache-Tomcat-6.0.20/lib <br/> and to simplify the process of obtaining database connections through the connection pool, the JDBC data source concept is introduced in jdbc2.0 specifications. <br/> javax. SQL. the datasource object is Java. SQL. the factory of the connection object can also be considered as the administrator of the database connection pool <br/> our program needs to obtain the database connection through the Tomcat server, first obtain the datasource object, then obtain the connection pool through the datasource object <br/> next we can use the code similar to the following in the program, to obtain the database connection object in the connection pool through the data source object <br/> context = new initialcontext (); <br/> datasource DS = (datasource) context. lookup ("Java:/COMP/ENV/jdbc/oracleds"); <br/> connection conn = Ds. getconnection (); <br/> javax. naming. context is the context object of JNDI. It acts as we call the Lookup () method of the context object in the current directory <br/>, you can obtain a data source object based on the specified jdni name <br/> where "Java:/COMP/ENV/" is mandatory, while "JDBC/oracleds" is in context. value of the parameter name set in the XML file <br/> and then use the getconnection () of the datasource object DS () method to obtain the database connection object conn <br/> after the connection object is used, the close () method of the object must be explicitly called in the program, release the resource <br/> to return the current connection object back to the connection pool, instead of actually closing the connection to the database.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.