Tomcat 8 (i) Tomcat common configuration

Source: Internet
Author: User
Tags documentation port number tomcat

Operating system: WIN8

JDK version: 1.7.0_51

JDK Directory: C:\Program files\java\jdk1.7.0_51

Tomcat version: 8.0.3

Tomcat Directory: D:\Program files\apache-tomcat-8.0.3

Tomcat 8 Download Address: http://tomcat.apache.org/download-80.cgi

Note: Tomcat 8 requires more than JRE7 of JRE

1. Tomcat environment variable Settings

1.1 Java environment variable settings

Right-click Computer-Properties-Advanced system settings-environment variables, in "System environment variables", set the following three variables (if the variable already has, click "Edit"; if the variable is not, click "New".) Format: Variable name = variable value)

Java_home = C:\Program files\java\jdk1.7.0_51

CLASSPATH =%java_home%\lib\dt.jar;%java_home%\lib\tools.jar;.

At the end of the variable value of path add;%java_home%\bin

1.2 Tomcat environment variable settings

In "System environment variables", set the following two variables

Catalina_home = D:\Program files\apache-tomcat-8.0.3

At the end of the variable value of path add;%catalina_home%\bin

Start Tomcat

Double-click the Startup.bat under the D:\Program files\apache-tomcat-8.0.3\bin directory (you can also perform startup.bat under cmd). There is no exception at the following interface, which indicates that Tomcat started successfully


Access Tomcat

Enter http://localhost:8080 under the browser to see the Tomcat home page

2. Modify the Tomcat Port

Tomcat listens to port 8080 by default, and if you want to modify this port number, open the

D:\Program Files\apache-tomcat-8.0.3\conf\server.xml, locate the following code snippet, modify the port property to

<connector port= "8080" protocol= "http/1.1"
               connectiontimeout= "20000"
               redirectport= "8443"/>

3. Tomcat set HTTPS

3.1 Making Xx.keystore files

Enter the following command at the command line:

Keytool-genkey-alias Tomcat-keyalg Rsa-keystore D:\test.keystore

(Keytool.exe in the C:\Program files\java\jdk1.7.0_51\bin directory.) Because the JDK environment variable is set, you can use Keytool directly at the command line)

The keystore password is optional, the last step of the key password is also optional, you can choose the same as the KeyStore password (press "Enter" key)

You can see the Test.keystore file under the D drive.

3.2 Modifying Server.xml

Open D:\Program Files\apache-tomcat-8.0.3\conf\server.xml and find the following code snippet

<!--
    port= "8443" protocol= "http/1.1" sslenabled= "true"
               maxthreads= "<connector" scheme= "https" Secure= "true"
               clientauth= "false" sslprotocol= "TLS"/>--

Opens the comment and modifies the connector label content, keystorepass the keystore password

<connector port= "8443" 
   	       protocol= "Org.apache.coyote.http11.Http11NioProtocol" sslenabled= "true"
               maxthreads= "Scheme=" "https" secure= "true"
   	       keystorefile= "D:\tomcat.keystore" keystorepass= "Password
               " Clientauth= "false" sslprotocol= "TLS"/>

Restart Tomcat, enter https://localhost:8443 under the browser to see the Tomcat home page

4. Modify the Tomcat Default Web project

Tomcat's Web project was placed in the D:\Program Files\apache-tomcat-8.0.3\webapps directory, with Tomcat bringing 5 Web projects: Docs, examples, Host-manager, All projects under WebApps are deployed when the manager and Root,tomcat are started

Enter http://localhost:8080/examples/index.html under the browser to access Examples's homepage (though it's a bit shabby ...). )


(Access http://localhost:8080/host-manager/index.jsp and http://localhost:8080/manager/index.jsp will prompt for user name, password, Tomcat's account questions are described below)

Obviously when you visit http://localhost:8080, Tomcat points to the root project by default, so what can you do to make Tomcat point to a custom project?

Open D:\Program Files\apache-tomcat-8.0.3\conf\server.xml and find the following code snippet

 

Add the following snippet to the host tag, and the Docbase property can specify the project name and set it to "examples"

<context path= "" docbase= "examples"  reloadable= "true" crosscontext= "true" >
 </Context>

Modified host Tag

   <valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs" prefix= "Localhost_access_
               Log "suffix=". txt "
               pattern="%h%l%u%t "%r"%s%b "/>
 
      </Host>
  

Restart Tomcat and enter http://localhost:8080 under the browser to see the examples home page

5. Tomcat Account

Access to http://localhost:8080/host-manager/index.jsp, you will be prompted to enter the user name, password, click "Cancel", will pop up the error page, based on this error page can find the way to set up Tomcat account

Open D:\Program Files\apache-tomcat-8.0.3\conf\tomcat-users.xml and add the following under the Tomcat-users tab

<role rolename= "Admin-gui"/>
 <user username= "Tomcat" password= "S3cret" roles= "Admin-gui"/>

Restart Tomcat, then access http://localhost:8080/host-manager/index.jsp, username input tomcat, password input s3cret, you can

6. Add Tomcat in Eclipse

Eclipse version: Eclipse Java EE IDE for Web Developers (Juno Service Release 2)

Select Window-preferences-server-runtime Environment-add and choose the Tomcat version, which version of Eclipse supports Tomcat with the highest version of 7,

So the following is configured with apache-tomcat-7.0.52


Enter the path to the TOMCAT7

JRE can be used with the workbench default JRE or the installed JRE


Click "Finish" to complete the eclipse under Tomcat settings

deploy a Web project under Eclipse

Right-click Web Project-run as-run on Server

Select the tomcat you just configured, click "Finish" to deploy the project

7. Modify Session Validity time

By default, the session is valid for 30 minutes. Open \conf\web.xml, modify the value of the session-timeout tag

<session-config>
        <session-timeout >30</session-timeout>
</session-config>

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.