Xml & Tomcat
Xml
What's the use of XML?
Define XML
Document declaration
简单声明,version : 解析这个xml的时候,使用什么版本的解析器解析
<?xml version="1.0" ?>
encoding : 解析xml中文字的时候,使用什么编码来翻译
<?xml version="1.0" encoding="gbk" ?>
standalone : no - 该文档会依赖关联其他文档,yes - 这是一个独立的文档
<?xml version="1.0" encoding="gbk" standalone="no" ?>
Encoding details
Xml进行存储时不是存储文字,而是存储这些文字对应的二进制。那么这些文字对应的二进制到底是多少呢?根据文件使用的编码来得到。
Therefore, there are two solutions to make our XML display Chinese normally
The ANSI you see when saving actually corresponds to our local code GBK.
For general use, it is recommended to use UTF-8 encoding to save, and encoding is UTF-8
Element definition (label)
Simple elements & complex elements
Definition of attributes
<stus>
<stu id="10086">
<name>张三</name>
<age>18</age>
</stu>
<stu id="10087">
<name>李四</name>
<age>28</age>
</stu>
</stus>
XML annotation
<!-- -->
如:
<?xml version="1.0" encoding="UTF-8"?>
<!--
//这里有两个学生
//一个学生,名字叫张三, 年龄18岁, 学号:10086
//另外一个学生叫李四 。。。
-->
CDATA area
If there are too many characters in a string, and it contains words like tags or keywords, and you don't want the XML parser to parse it, you can use CDATA to wrap it. However, this CDATA is rarely seen, usually when the server returns data to the client.
<des><![CDATA[<a href="http://www.baidu.com">这是一个描述</a>]]></des>
XML parsing
XML parsing method (frequently asked in interview)
APIs for these two parsing methods
jaxp sun公司 比较繁琐
jdom
dom4j 使用比较广泛
Dom4j basic usage
element.element("stu") : 返回该元素下的第一个stu元素
element.elements(); 返回该元素下的所有子元素。
XPath usage of Dom4j
XML constraint [understand]
In the following documents, the ID value of the attribute is the same, which is impossible in life. And there are several names of the second student, usually very few. So how do you specify that the ID value is unique, or that the element can only appear once and cannot appear multiple times? It even stipulates that only specific element names can appear in it.
<stus>
<stu id="10086">
<name>张三</name>
<age>18</age>
<address>深圳</address>
</stu>
<stu id="10086">
<name>李四</name>
<name>李五</name>
<name>李六</name>
<age>28</age>
<address>北京</address>
</stu>
</stus>
DTD
语法自成一派,早起就出现的,可读性比较差。
--
<!ELEMENT stus (stu)> : stus 下面有一个元素 stu , 但是只有一个
<!ELEMENT stu (name,age)> stu下面有两个元素 name,age 顺序必须name-age
<!ELEMENT name (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ATTLIST stu id CDATA #IMPLIED> stu有一个属性 文本类型, 该属性可有可无
元素的个数:
+ 一个或多个
* 零个或多个
? 零个或一个
属性的类型定义
CDATA : 属性是普通文字
ID : 属性的值必须唯一
<!ELEMENT stu (name,age)> 按照顺序来
<!ELEMENT stu (name | age)> 两个中只能包含一个子元素
Schema
其实就是一个xml,使用xml的语法规则,xml解析器解析起来比较方便,是为了替代DTD。
但是Schema约束文本内容比DTD的内容还要多,所以目前也没有真正意义上的替代DTD。
约束文档:
<!-- xmlns : xml namespace : 名称空间 / 命名空间
targetNamespace : 目标名称空间 。 下面定义的那些元素都与这个名称空间绑定上。
elementFormDefault : 元素的格式化情况。 -->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.itheima.com/teacher"
elementFormDefault="qualified">
<element name="teachers">
<complexType>
<sequence maxOccurs="unbounded">
<!-- 这是一个复杂元素 -->
<element name="teacher">
<complexType>
<sequence>
<!-- 以下两个是简单元素 -->
<element name="name" type="string"></element>
<element name="age" type="int"></element>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
实例文档:
<?xml version="1.0" encoding="UTF-8"?>
<!-- xmlns:xsi : 这里必须是这样的写法,也就是这个值已经固定了。
xmlns : 这里是名称空间,也固定了,写的是schema里面的顶部目标名称空间
xsi:schemaLocation : 有两段: 前半段是名称空间,也是目标空间的值 , 后面是约束文档的路径。
-->
<teachers
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.itheima.com/teacher"
xsi:schemaLocation="http://www.itheima.com/teacher teacher.xsd">
<teacher>
<name>zhangsan</name>
<age>19</age>
</teacher>
<teacher>
<name>lisi</name>
<age>29</age>
</teacher>
<teacher>
<name>lisi</name>
<age>29</age>
</teacher>
</teachers>
Role of namespaces
If an XML wants to specify its constraint rules, assuming that DTDs are used, the XML can only specify one DTD, not multiple DTDs. However, if an XML constraint is defined in a schema and there are multiple schemas, it is OK. Simply put, an XML can reference multiple schema constraints, but only one DTD constraint can be referenced. The function of a namespace is to specify which set of constraint rules the element uses when writing an element. By default, if there is only one set of rules, it can be written like this.
<name>张三</name>
AA and BB correspond to two rules
<aa:name></aa:name>
<bb:name></bb:name>
Program architecture
Web games
advantage:
有一部分代码写在客户端,用户体验比较好。
Disadvantages:
服务器更新,客户端也要随着更新,占用资源大。
advantage:
客户端只要有浏览器就可以了,占用资源小,不用更新。
Disadvantages:
用户体验不佳。
The server
Web server software
Web applications need server support html
Tomcat apache
WebLogic BEA
Websphere IBM
IIS 微软
Tomcat installation
Introduction to Tomcat directory
bin
包含了一些jar,bat文件 startup.bat
conf
tomcat的配置 server.xml web.xml
lib
tomcat运行所需的jar文件
logs
运行的日志文件
temp
临时文件
webapps
发布到tomcat服务器上的项目就存放在这个目录
Work (not in charge at present)
jsp翻译成的class文件存放在这个目录
How to publish a project to Tomcat
localhost : 本机地址
1. Copy this file to webapps / root and access it in the browser:
http://localhost:8080/stu.xml
* 在webaps下面新建一个文件夹xml,然后拷贝文件放置到这个文件夹中
http://localhost:8080/xml/stu.xml http://localhost:8080 : in fact, it corresponds to webapps / root http://localhost:8080/xml/ : corresponds to webapps / XML
使用IP地址访问:
http://本机IP/xml/stu.xml
2. Configure virtual path
Use localhost: 8080 to open the Tomcat home page, find the Tomcat document entry on the left, click in, then find the context entry on the left, and click enter.
http://localhost:8080/docs/config/context.html
3. Configure virtual path
Configuring Tomcat for eclipse
Summary:
xml
1. 会定义xml
2. 会解析xml
dom4j 基本解析
Xpath手法
tomcat
1. 会安装 ,会启动 , 会访问。
2. 会设置虚拟路径
3. 给eclipse配置tomcat
I haven't used the grammar rules of markdown to write notes for a long time. Some of them have forgotten. I still need to learn it systematically when I have time. The contents of many code blocks can be displayed on markdownpad2, but they can't be seen in the background preview of the blog park. It's a headache. It took a long time to debug slowly. It seems more convenient to separate markdownpad2 from the left and right