1. How to modify the Tomcat port
In some cases, you may need to modify the port 8080 for Tomcat listening, such as:
A. Need to start two Tomcat servers
B. A service takes up 8080 ports (1433,1521,3306 ...)
Windows View Port Usage command: Netstat-an
Ways to modify the Tomcat port:
Modify the port= "8080" data in the ~tommcat/conf/server.xml file to change the 8080 to the port number you need.
Port number range: 1-65535 (actually some of the ports are already used), generally 1-1024 is not allowed to use, change
The ports in the enclosure are called known ports.
2. How to set up a virtual directory
Why should we set up a virtual directory?
At present, our site is placed under the default directory under ~tomcat~/webapps. However, in some cases, it may be necessary to
The site is placed in a different directory, such as:
The disk space where the a.tomcat is not enough.
B. For unified management, want to be placed in a specific directory, rather than under the default ~tomcat~/webapps.
How to set up a virtual directory.
Open the Conf subdirectory under the Tomcat installation directory, modify the Server.xml file, and add the following information in the appropriate location:
<context path= "/yoursite" [Your site name, which is the home folder name] dobase= "The disk entries stored at the d:\mysite[site
"debug=" 0 "/>
Note: The above configuration code needs to be between methods
3. How to set a password for the Tomcat administrator
Why to set the administrator password.
In the Tomcat-users.xml file in the Tomcat installation directory, you can set a password for the administrator to prevent illegal users
Telnet to Tomcat.
A. By default, the administrator's password is a blank password, so that the rogue may publish a site remotely and in a servlet
If there are some horrible statements (such as rebooting, shutting down, etc...) )
Using the password to empty the process of destruction
A. Using the JDK's own jar tool to package a compromised site into a *.war file This step, you first need to set the path command as follows:
Set path=%path%; your JDK directory \ Bin so you can use the JAR command in any directory, then switch the path to the one that needs to be packaged
The folder directory; The package command is: JAR-CVF War file name * *
B. Publishing a site to Tomcat through the Tomcat administration page
C. Visit the servlet with the corrupted code so that you will be hacked.
To set the administrator password:
In the Tomcat-users.xml file in the Tomcat installation directory, you can set a password for the administrator to prevent illegal use
Remote Login to Tomcat. In the appropriate location of the Tomcat-users.xml file, set the password for the administrator. <user
Username= "Xushouwei" password= "Xushouwei" roles= "Standard,manager,admin" >
4. How to set up a data source and connection pool
Why use data sources and connection pooling.
Every time the Java source program operates the database, it needs to load the driver to get a connection and then return a result. This is too much time.
, if our Sina and other large-scale website every day may have thousands or even hundreds of millions of visits every time the visit will check the database,
Even if the driver is loaded for a short time, the number of accesses will become slow.
Schematic diagram of configuration data source and connection pooling:
5. How to configure the data source and connection pool.
A. By modifying the%tomcat_home%/conf/server.xml file, add the following code at the specified location:
<context path= "/mywebsite" docbase= "d:\MyWebSite" debug= "0" >
<!--name: Set a name for the data source, Auth: Indicates who managed the data, type: Types--
<resource name= "Xushouwei" auth= "Container" type= "Javax.sql.DataSource"/>
<resourceparams name= "Xushouwei" >
<!--factory Settings--
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<!--drive settings, which are placed under Tomcat common/lib, or in the site's own Lib directory--
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<!--settings url-->
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=spdb</value>
</parameter>
<parameter>
<!--set the user name of the connection database--
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<!--set the password for the connection database--
<name>password</name>
<value>xushouwei</value>
</parameter>
<parameter>
<!--the maximum number of active connections in the connection pool--
<name>maxActive</name>
<value>200</value>
</parameter>
<parameter>
<!--the largest number of reserved idle connections in the connection pool-
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<!--The maximum wait time for clients in the queue pool, measured in seconds-
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
B. Configuring with the Tomcat Management interface
6. How to use data sources and connection pooling.
A. If you are connecting to a database by using a connection pool, you should:
Context ctt=new Javax.naming.InitialContext ();
DataSource ds= (DataSource) ctt.lookup ("Name of the java:comp/env/data source");
Ct=ds.getconnection ();
Note: "Name of the java:comp/env/data source" This is a fixed notation, meaning to get the meaning of the configuration environment.