An Overview of the Java Web How It Was Made

1. XML Basics

DTD constraint

Through a case to briefly understand the DTD constraints, create a book.xml file

Please add a picture description

<?xml version="1.1" encoding="UTF-8"?>
<书架>
 	<>
 		<书名>徒然草</书名>
 		<作者>吉田兼好</作者>
 		<售价>34.00元</售价>
 	</>
 	<>
 		<书名>精通Spring框架</书名>
 		<作者>魏赫布</作者>
 		<售价>49.00元</售价>
 	</>
</书架>

Classroom exercise: convert XML file into MySQL table Please add a picture description
Please add a picture description
Please add a picture description
Classroom exercise: convert XML file into JSON Please add a picture description
and view it with JsonView tool software Please add a picture description
Create book.dtd filePlease add a picture description

<!ELEMENT 书架 (书+)>
<!ELEMENT  (书名,作者,售价)>
<!ELEMENT 书名 (#PCDATA)>
<!ELEMENT 作者 (#PCDATA)>
<!ELEMENT 售价 (#PCDATA)>

book.dtd is a simple DTD constraint document. Each element is written according to the constraints specified by the book.dtd document.

Introduction of DTD

(1) Import local DTD files

Modify the file book.xml and introduce the local DTD file book.dtd in the XML document
Please add a picture description

<?xml version="1.1" encoding="UTF-8"?>
<!DOCTYPE 书架 SYSTEM "book.dtd">
<书架>
 	<>
 		<书名>徒然草</书名>
 		<作者>吉田兼好</作者>
 		<售价>34.00元</售价>
 	</>
 	<>
 		<书名>精通Spring框架</书名>
 		<作者>魏赫布</作者>
 		<售价>49.00元</售价>
 	</>
</书架>

(2) Introduce public DTD files

To introduce a public DTD file, you need to use the PUBLIC attribute in the DOCTYPE declaration statement

<!DOCTYPE web-app PUBLIC 
	"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
	 "http://java.sun.com/dtd/web-app_2_3.dtd">

Modify book.xml and directly embed the book.dtd file in the book.xml documentPlease add a picture description

<?xml version="1.1" encoding="UTF-8"?>
<!DOCTYPE 书架 [
	<!ELEMENT 书架 (书+)>
	<!ELEMENT  (书名,作者,售价)>
	<!ELEMENT 书名 (#PCDATA)>
	<!ELEMENT 作者 (#PCDATA)>
	<!ELEMENT 售价 (#PCDATA)>
]>
<书架>
 	<>
 		<书名>徒然草</书名>
 		<作者>吉田兼好</作者>
 		<售价>34.00元</售价>
 	</>
 	<>
 		<书名>精通Spring框架</书名>
 		<作者>魏赫布</作者>
 		<售价>49.00元</售价>
 	</>
</书架>

Schema Constraints

Documentation for Schema Constraints

The function of XML Schema is much more powerful than DTD, but the corresponding syntax is also much more complicated than DTD.
Look at a simple Schema document

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="root"  type="xs:string"/>
</xs:schema>

Please add a picture description

Format for declaring namespaces

Create book2.xml and learn the use of namespaces in the book2.xml document.Please add a picture description

<?xml version="1.1" encoding="UTF-8"?>
<lzy:书架 xmlns:lzy="http://www.lzy.org/xmlbook/schema">
 	<lzy:>
 		<lzy:书名>徒然草</lzy:书名>
 		<lzy:作者>吉田兼好</lzy:作者>
 		<lzy:售价>34.00元</lzy:售价>
 	</lzy:>
 	<lzy:>
 		<lzy:书名>精通Spring框架</lzy:书名>
 		<lzy:作者>魏赫布</lzy:作者>
 		<lzy:售价>49.00元</lzy:售价>
 	</lzy:>
</lzy:书架>

Tomcat server

Tomcat official website

https://tomcat.apache.org/
Please add a picture description

Download the Tomcat compressed package

https://tomcat.apache.org/download-80.cgi
Please add a picture description
download locally
Please add a picture description

Tomcat installation and start

Please add a picture description

1. Decompress the Tomcat compressed package.
You can decompress the compressed package to any location. The final path should not contain Chinese characters and spaces. For example, decompress to the root directory of the D drive. After decompression, an apache-tomcat-8.5.86 folder will be generated.

2. The directory structure of Tomcat

Open the apache-tomcat-8.5.86 folder, you will see 7 directories inside

3. Configure Tomcat environment variables

Create a new CATALINA_HOME environment variable, then modify the Path variable and add %CATALINA_HOME%\bin;
Please add a picture description

4. Start the Tomcat server

Many script files are stored in the bin directory of the Tomcat installation directory, among which startup.bat is the script file for starting Tomcat.Please add a picture description
Please add a picture description
Please add a picture description

5. Access resources on the server

Open the webapps directory of the Tomcat server Please add a picture description
, enter the ROOT directory, there is the homepage of the Tomcat server - index.jsp Please add a picture description
Visit the homepage through a browser, Please add a picture description
visit the static resources (pictures, text, audio and video) in the ROOT directory , Please add a picture description
create a webpage in the Root - welcome.html, Please add a picture description
visit http://localhost:8080/welcome.txt or http://127.0.0.1:8080/welcome.html in the browser , Please add a picture description
or use the IP address of the machine Please add a picture description
to visit http://10.0.1.30:8080/welcome.html Please add a picture description
Create an application directory shop in webapps, and create a text file in this directory - whipser.txt Access in a Please add a picture description
browser - http://localhost:8080/shop/whisper.txtPlease add a picture description

6. Shutdown of the Tomcat server

Many script files are stored in the bin directory of the Tomcat installation directory, among which shutdown.bat is the script file for shutting down Tomcat. Please add a picture description
After closing the Tomcat server, and then visiting http://localhost:8080/, an error will be reportedPlease add a picture description

7. Solve the problem of Chinese garbled characters in the Tomcat startup window

You can see that there are Chinese garbled characters in the window that pops up after starting the Tomcat server. Please add a picture description
Modify the logging.properties file in the conf directory Please add a picture description
and comment out all five statements related to encoding Please add a picture description
. Restart the Tomcat server and check the information in the startup window to see if there are any Chinese garbled characters.Please add a picture description

tomcat-diagnostics

Goal: Master Tomcat diagnosis, how to solve the error that the command line window flashes after Tomcat starts

1. After startup, the command window flashes by

When double-clicking the startup.bat script file in the bin directory, the command line window flashes by. In this case, since the error message cannot be viewed, it is impossible to diagnose Tomcat and analyze the cause of the error. At this time, you can start a command line window first. In this command line window, switch the directory to the bin directory in the Tomcat installation directory, and then execute the startup.bat command in this window, and you will see an error message.
Please add a picture description
Please add a picture description
Please add a picture description

2. Tomcat port number is occupiedPlease add a picture description

Please add a picture description
Please add a picture description
Visit http://localhost:8888Please add a picture description

Hands-on: Creating a Web Application

Goal: Master how to configure Tomcat in IDEA and create web applications

1. Method 1: Add Web functions to the Java project

Create a Java project - WebDemo01 Please add a picture description
Set the project name and save location Please add a picture description
Click the [Finish] button Please add a picture description
to add Web functions to the project in the project structure window, switch to Modules and click the Please add a picture description
[+] button to add Web functions Please add a picture description
Please add a picture description
On the Tomcat server, switch to the [Server] tab and click the [OK] button to create a homepage in the web directory - index.html , start Please add a picture description
the tomcat server , and check the results. Of course, writing index.html also has the same effectPlease add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description

Create a Java Web project directly

Create a new Java Enterprise project, select Web Application (4.0)Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description

Guess you like

Origin blog.csdn.net/qq_64505257/article/details/130982752