JavaWeb Concepts What is JavaWeb? JavaWeb is the general term for writing all programs in the Java language that can be accessed by a browser. We call it javaWeb.

A) What is a request A request is when a client sends data to a server.

B) What is a response A response is the data that the server sends back to the client.

C) The relationship between request and response

Where there is a request, there is a response.



Classification of Web resources

Web resources are classified into static resources and dynamic resources according to the technologies implemented and the effects presented.

Static resources: HTML pages, CSS files, JS files, images, videos, texts, etc

Dynamic resources: JSP dynamic pages, Servlet programs

Common Web servers Web server Overview Tomcat: A Web server provided by the Apache organization that supports JSP and servlets. It is a lightweight javaWeb container (server) and currently the most widely used javaWeb server (free).

JavaWeb container ===>>> > is understood as a server (Tomcat)

Jboss: Is an open source JavaEE compliant, pure Java EJB server that supports all of the JavaEE specifications (free).

GlassFish: a JavaWeb server developed by Oracle, GlassFish is a robust commercial server with production-quality (few applications).

Resin: is a CAUCHO company’s product, is a very popular server, servlet and JSP provide good support, the performance is also better, Resin itself using JAVA language development (charge, more applications).

WebLogic: Oracle’s product is the most widely used Web server. It supports the JavaEE specification and is constantly improved to meet new development requirements. It is suitable for large projects (for a fee, not used much, suitable for large companies).

Mapping between Tomcat server and Servlet versions

The current version is 7.*/8.*



All servlets are defined according to version 2.5

2.5 Is configured in web. XML

3.0 is all about annotations

Use of Tomcat a) Installation Find the version of the zip package you need to install, decompress to the directory you need to install. Apache-tomcat-7.0.85 -windows-x64.zip Decompress apache-tomcat-7.0.85 directory b) Directory This section describes the bin directory for storing executable programs of the Tomcat program. Conf Store the configuration file of the Tomcat server lib Store the JAR package of the Tomcat runtime Directory logs Store the output diary of the Tomcat runtime Temp is a temporary directory of Tomcat. Webapps are used to deploy web projects Used to store Servlet programs after JSP translation and serialization files for Session activation and passivation

C) How to start the Tomcat server 1). Find the startup.bat file in the bin directory of the Tomcat server installation directory and double-click it to start the Tomcat server. How do I test the Tomcat Server startup? Open a browser, and enter the IP address of the access test in the address box: 1, http://localhost:8080 (local) 2, http://127.0.0.1:8080 (local) 3, http://192.168.10.100(IP address of your computer):8080

If the following page is displayed, the Tomcat server is successfully started.



2) Another way to start Tomcat: Catalina Run

A) Open the Window command line window

B) CD to the bin directory in your Tomcat directory

C) On the CLI, run catalina run and press Enter



Configure the tomcat port(**** key)

The default tomcat port is 8080 (access port)

The default HTTP port is 80

If http://www.baidu.com is entered during access, it is equivalent to http://www.baidu.com:80

After the actual project goes live, 80 is usually used.

1) Find the tomcat directory /conf/server.xml



2) Change the value of port to 80

After changing the listening port of Tomcat, restart the Tomcat server for the modification to take effect



3) Then type in your browserhttp://127.0.0.1:80 或 http://127.0.0.1Access to the test



Access successful!!

Generally we use the tomcat default port 8080 for access, so we still need to change back.

The following common situations occur when the Tomcat server fails to start:

1. JAVA_HOME environment variable not configured (or incorrectly configured)



The following are common configuration errors of JAVA_HOME:

Java_home (uppercase) error =====>>>>> Correct: javA_HOME

Java-home (underline, not minus) error =====>>>>> Correct: JAVA_HOME

JAVA_HOME, but the value is configured to C:\Java\jdk1.8.0_102\bin error.

It should be configured to C:\Java\jdk1.8.0_102

The port number required by the Tomcat server is occupied by other programs.



Tomcat’s stop

1. Go to the bin directory of the Tomcat server and double-click shutdown.bat to stop the Tomcat server. (key)

2. Go to the Tomcat server window and click the X button

3. Locate the Tomcat server window and make it the current window. Press the shortcut key Ctrl+C

Common ways to deploy projects to Tomcat(**** key)

Case 1:

Generally, a Web project is a directory, and each file in the directory is a resource under the Web project.



Each directory in the project directory has a corresponding relationship with the address in the browser address bar.

Case 2:

Copy the website directory to the tomcat/webapps directory —-

There is a web site (a folder), copy the folder to the Tomcat webapps directory.

The name of the folder is the directory to which the site or project is accessed



Then type in the address bar:http://127.0.0.1:8080/javawxid/xxxxx.html

http:// is a protocol

127.0.0.1 is the IP address of the server you want to access

8080 is the port number monitored by Tomcat

Javawxid is the name of the project you want to access in the Webapps directory

Xxxx.html is the file name to access in this directory

What is the difference between holding an HTML page to a browser and typing http://ip: port number/project name/access?

Access to the ROOT project in the Webapps directory When you enter http://ip:port/ in the browser address box, you can access the ROOT project. When you enter http://ip:port/ project name/in the browser address box, you can access the index.html page of the specified project name

If there is a ROOT project under webapps. The ROOT directory can be accessed by omitting the project name /

Create a new hello. HTML file in the ROOT directory with the following contents:



The inputhttp://127.0.0.1:80/hello.html 或 http://127.0.0.1/hello.htmlAccess to the test



Note: the port number is consistent, if is the default port number is http://127.0.0.1:8080/hello.html

Access successful!!

Integrate Tomcat and Eclipse development tools(*** commonly used must be mastered)

Open the Eclipse Server view window

In the first case, open the Servers window directly



In the second case, the search Servers window opens

Figure 1 opens the total Eclipse view



Figure 2: Enter the Server filter out Server window option



The Servers server window has opened successfully, as shown below:



Creating a Tomcat Server

1) In the Servers window, click the text prompt to create a server connection. The diagram below:



2) Create a new Tomcat server instance



Note: If your Tomcat is 7.0 choose your own

3) Click Browse button to open the directory selection window. Select the Tomcat decompression directory



4) Select the Tomcat directory and click OK



5) After selecting the Tomcat directory, click the “Next” button to continue the operation

6) Click the “Finish” button to Finish the operation



7) Tomcat server created successfully!!



When Tomcat and Eclipse are integrated successfully. In Eclipse there is a Servers project directory, which is the configuration file project after Tomcat integration.

Tip: Just remember. The Servers project should never be deleted. Don’t turn it off. Otherwise, Tomcat cannot start.

The diagram below:



Start the Tomcat server in Eclipse

1) Start the Tomcat server in Debug mode



“Debug mode starts!!



Tomcat successfully started console message!!



2) Start the Tomcat server in Run mode



Start display in Run mode



Tomcat successfully started console message!!



Stop the Tomcat server in Eclipse

Violent shutdown of Tomcat (equivalent to unplugging a computer. No shutdown preparation was performed.



Stop Tomcat normally (equivalent to clicking the Shutdown button in the operating system, perform shutdown save operation, and then shutdown)



Create a dynamic Web project

1) Create a dynamic Web project first



2) Configure project options



3) Select generate web. XML configuration file



4) Dynamic Web project created!!



Introduction and description of the Web project directory



After we have created the dynamic Web project, we access the following path through the browser, for example:

http://127.0.0.1:8080/day06

HTTP: indicates that the access protocol is HTTP

127.0.0.1 indicates the server to be accessed

Port 8080 indicates which program in the server to access Tomcat server (Multiple Tomcat servers can be installed on one server)

Day06 tells the server which project to access (Tomcat can run multiple projects simultaneously). The default access is index.html or index.htm or index.jsp.)

http://127.0.0.1:8080/day06/1.html said access IP address 127.0.0.1 for local server, port 8080 Tomcat application server. Access the 1.html file in the day06 project

Manually deploy the project to Tomcat(Understand the content, just know)

1. Copy the WebContent directory of the Web project to the Tomcat webapps directory.





2. Change the webContent directory in the WebApps directory to the project name you need

3. Manually copy the classes directory in the Build directory of Eclipse to the web-INF directory of the deployment project

Eclipse working interval project:



The tomcat directory is in the web-INF directory of the project



The entire process of manually deploying projects to Tomcat is cumbersome. And extremely inconvenient project code debugging.

Since manual deployment of the Web project, so troublesome. That’s why you need to integrate Tomcat into Eclipse.

Right-click Run on Server menu to do what? 1. The Web project has been deployed on the server. 2, open the browser 3, in the browser, directly for you to access the resource you want to access

Publish the project to Run in Tomcat

1) Select the project you want to publish first. Right click run



2) Select a server



3) Click Finish and run the server



4) Results of heat distribution and operation



Once Tomcat is integrated into Eclipse, the primary role is to access deployment projects and debug applications

Configure the Tomcat Web project path in Eclipse

1) Open the Servers window and double-click Tomcat V6.0 Server to open the Tomcat configuration window



Here are three different options for Eclipse to publish the project.





Question 1: What is the role of integrating Eclipse and Tomcat?

The main purpose of integrating Tomcat and Eclipse is to facilitate deployment of engineering and debugging programs. And the integration is just for the convenience of testing the program.Copy the code

Question 2: Why can’t the original Tomcat project be accessed after integration?

The consolidated Tomcat is not the same server as your original Tomcat installation. A: QQ (originally installed Tomcat) a1 A2 B: QQ (integrated Tomcat) b1 B2 B: QQ cannot access A1, A2 integrated Tomcat into Eclipse, just for debugging.Copy the code

Tomcat location – options description:

  1. User workspance Metadata (does not modify Tomcat Installation) is stored in the Working interval directory of Eclipse

    Eclipse workspace directory. The metadata. The plugins \ org eclipse WST. Server core \ tmp0 \ have a copy of a tomcat

    All were deployed web project will them to eclipse workspace directory. The metadata. The plugins \ org eclipse WST. Server core \ tmp0 \ wtpwebapps directory

  2. User Tomcat Installation (takes control of Tomcat Installation) Makes changes in the original Tomcat directory

    All web projects are published to the \ wTPwebapps directory in the Tomcat directory

  3. User custom location (does not modify Tomcat installtion) Customize a directory to deploy the Web project

For example, the operation is as follows:

1: Select a customized directory



Two: select your custom directory and click OK. Some of the Tomcat directories will then be copied over. Bucher’s project is also under the wTPWebapps directory in this directory



Three: select the project you want to deploy heat, right-click the menu Run As – >>> Run on Server

Put the project into the directory you just defined.



Four: choose which server you need to run your current Web project.

If Always Use this server when running this project is selected, the selected server is used to run the server next time by default.



Five: After Tomcat is started and the Web project is successfully deployed. To view





Six: enter the test view in the browser



How to set right click run project, open external browser access.

The Servers project is used when we create the Tomcat server. In Eclipse, a Servers project is created, which holds the configuration files for all the Servers. This is where we will change the configuration options of the Tomcat server integrated in Eclipse.

Common error starting Tomcat in Eclipse

If this error occurs, double-click shutdown.bat in the bin directory of the original Tomcat