Article Directory
1. XML Basics
DTD constraint
Through a case to briefly understand the DTD constraints, create a book.xml file
<?xml version="1.1" encoding="UTF-8"?>
<书架>
<书>
<书名>徒然草</书名>
<作者>吉田兼好</作者>
<售价>34.00元</售价>
</书>
<书>
<书名>精通Spring框架</书名>
<作者>魏赫布</作者>
<售价>49.00元</售价>
</书>
</书架>
Classroom exercise: convert XML file into MySQL table
Classroom exercise: convert XML file into JSON
and view it with JsonView tool software
Create book.dtd file
<!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
<?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 document
<?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>
Format for declaring namespaces
Create book2.xml and learn the use of namespaces in the book2.xml document.
<?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/
Download the Tomcat compressed package
https://tomcat.apache.org/download-80.cgi
download locally
Tomcat installation and start
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;
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.
5. Access resources on the server
Open the webapps directory of the Tomcat server
, enter the ROOT directory, there is the homepage of the Tomcat server - index.jsp
Visit the homepage through a browser,
visit the static resources (pictures, text, audio and video) in the ROOT directory ,
create a webpage in the Root - welcome.html,
visit http://localhost:8080/welcome.txt or http://127.0.0.1:8080/welcome.html in the browser ,
or use the IP address of the machine
to visit http://10.0.1.30:8080/welcome.html
Create an application directory shop in webapps, and create a text file in this directory - whipser.txt Access in a
browser - http://localhost:8080/shop/whisper.txt
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.
After closing the Tomcat server, and then visiting http://localhost:8080/, an error will be reported
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.
Modify the logging.properties file in the conf directory
and comment out all five statements related to encoding
. Restart the Tomcat server and check the information in the startup window to see if there are any Chinese garbled characters.
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.
2. Tomcat port number is occupied
Visit http://localhost:8888
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
Set the project name and save location
Click the [Finish] button
to add Web functions to the project in the project structure window, switch to Modules and click the
[+] button to add Web functions
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
the tomcat server , and check the results. Of course, writing index.html also has the same effect
Create a Java Web project directly
Create a new Java Enterprise project, select Web Application (4.0)