J2EE Notes 2, j2ee notes

Source: Internet
Author: User

J2EE Notes 2, j2ee notes

1. Deploy and start the tomcat server.
1). Extract the apache-tomcat-6.0.16.zip to a non-Chinese directory
2) configure an environment variable. java_home (pointing to the JDK installation root directory) or jre_home
3) double-click startup. bat in the apache-tomcat-6.0.16 \ bin directory to start the server.
4). Enter localhost: 8080 in the browser to check whether Tomcat is correctly installed.
5) If a Tomcat application has been started and the same Tomcat application is started again, an exception is thrown:
Java.net. BindException: Address already in use: JVM_Bind: 8080
Because the port is occupied.

2. Tomcat: open-source Servlet container.

3. You can modify the configuration information in the server. xml file to modify the Tomcat server port number:

<Connector port = "8989" protocol = "HTTP/1.1"
ConnectionTimeout = "20000"
RedirectPort = "8443" type = "regxph" text = "yourobjectname"/>

Change the port value to another port number.

4. To enable Tomcat server in any directory
4.1 Add D: \ apache-tomcat-6.0.16 \ bin to path

After successful addition, if you start the Tomcat server through startup in any directory, a message is displayed:

The CATALINA_HOME environment variable is not defined correctly
This environment variable is needed to run this program

That is, the environment variable CATALINA_HOME must be set.

5. Set the CATALINA_HOME environment variable:
5.1 By reading the startup. bat batch processing file, we can see that there is a bin directory under the CATALINA_HOME environment variable,
The bin directory has another catalina. bat file. It can be seen that CATALINA_HOME points to Tomcat.
Installed root directory

Set the Tomcat root directory to the CATALINA_HOME environment variable.

In this case, the Tomcat server can be started and shut down in any directory through startup. bat and shutdown. bat.

6. Continue reading the startup. bat file and find that the tomcat server is started with the catalina. bat file.

Enter catalina in the command line window and the prompt is as follows:

Commands:
Debug Start Catalina in a debugger
Debug-security Debug Catalina with a security manager
Jpda start Start Catalina under JPDA debugger
Run Start Catalina in the current window
Run-security Start in the current window with security manager
Start Start Catalina in a separate window
Start-security Start in a separate window with security manager
Stop Stop Catalina
Version What version of tomcat are you running?

The catalina command has the following optional parameters.

Run: Start the server in the same command line window of catalina.
Start: start the server in a new window.
Stop: Shut down the server.

7. The first WEB application is developed and deployed to the Tomcat server for running.

1) create a Java Project in Eclipse
2) create a directory structure for WEB development under the Java Project

-WebContent
WEB-INF
-Classes (the compiled class file must be placed in this directory .)
-Lib
-Web. xml (copied from apache-tomcat-6.0.16 \ webapps \ docs \ WEB-INF,
Can not be modified)
Html page
JSP page
Picture...

3) create a Person class under src

Package com. atguigu. test;

Public class Person {

Public String getPersonInfo (){
Return "person info ...";
}

}

4) copy the class file (including package) corresponding to the manual Person class to the classes directory.

You can modify the default output directory to automatically put the compiled class under the classes directory:

5) create a JSP file in the WebContent directory:

<% @ Page import = "com. atguigu. test. Person" %>
<% @ Page language = "java" contentType = "text/html; charset = ISO-8859-1"
PageEncoding = "ISO-8859-1" %>


<%
Person person = new Person ();
System. out. print (person. getPersonInfo ());
%>

6) copy the WebContent directory to the Tomcat webapps directory and change it to helloworld.

7) Enter http: // localhost: 8989/helloworld/hello. jsp in the address bar of the browser.
View the command line printing information

8) configure the Web application in any directory:
Create the catalina \ localhost directory in the conf directory, and then test
This Web application creates a test. xml file. edit the file and enter the following content:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Context
DocBase = "E :\\ Java \ Source \ atguigu \ java-1 \ firstWebApp \ WebContent"
Reloadable = "true"/>

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.