惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
T
Threatpost
G
Google Developers Blog
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
Hacker News: Ask HN
Hacker News: Ask HN
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Schneier on Security
B
Blog
V2EX - 技术
V2EX - 技术
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
Schneier on Security
Schneier on Security
F
Fortinet All Blogs
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
S
Security @ Cisco Blogs
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
Project Zero
Project Zero
I
Intezer
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
SecWiki News
SecWiki News
Martin Fowler
Martin Fowler

博客园 - pmh905001

爬虫-今日头条我的收藏-反爬虫分析(六) pycharm的没落,vs code的兴起 爬虫-今日头条我的收藏-增量式下载网页内容(五) 爬虫-今日头条我的收藏-增量式导入到Elastic Search(四) 今日头条源代块一行代码很长情况下的拖动问题 爬虫-今日头条我的收藏-增量式导入到mongodb(三) 爬虫-今日头条我的收藏-增量式(二) openpyxl一个bug 爬虫-今日头条我的收藏(一) pystray被隐藏菜单项显示出来的问题 pyinstaller生成的exe程序使用使用默认程序打开execel文件 pyinstaller生成的exe文件的所在的工作目录问题 windows下python的keyboard库在锁屏之后再次登陆快捷键(热键)失效问题 pyinstaller 报错ImportError: No module named _bootlocale windows下gitbash 鼠标左键选中文字自动自行终止命令 ctrl+c ^C spring-security 如何使用用户名或邮箱登录 struts2的优缺点以及如何改造 jetty-maven-plugin 版本导致jetty启动失败问题 Eclipse下pom.xml的提示 Cannot access defaults field of Properties
tomcat jndi context.xml的特殊字符转义问题
pmh905001 · 2023-05-23 · via 博客园 - pmh905001

在tomcat中配置名为jdbc/moikiitos的jndi (例如:$TOMCAT_HOME/conf/context.xml)数据连接配置成如下:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource 
        name="jdbc/moikiitos"
        auth="Container"
        type="javax.sql.DataSource"
        username="root"
        password="root"
        driverClassName="com.mysql.cj.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/db_name?useUnicode=true&characterEncoding=utf8"
        maxActive="8"
        maxIdle="4"
    />
</Context>

启动应用报错

org.xml.sax.SAXParseException; systemId: file:$TOMCAT_HOME/conf/context.xml; lineNumber: 12; columnNumber: 79; 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾。

改成这样依然报错:

<?xml version="1.0" encoding="UTF-8"?>
<Context>

    <!-- These are the settings for Tomcat -->
    <Resource 
        name="jdbc/moikiitos"
        auth="Container"
        type="javax.sql.DataSource"
        username="root"
        password="root"
        driverClassName="com.mysql.cj.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/db_name?useUnicode=true&;characterEncoding=utf8"
        maxActive="8"
        maxIdle="4"
    />

</Context>
严重: Parse error in context.xml for /test
org.xml.sax.SAXParseException; systemId: file:$TOMCAT_HOME/conf/context.xml; lineNumber: 12; columnNumber: 62; 在实体引用中, 实体名称必须紧跟在 '&' 后面。

正常的数据库连接本应该是这样:

jdbc:mysql://localhost:3306/moikiitos?useUnicode=true&characterEncoding=utf8

为何在context.xml就解析失败呢? 后来查了一下,原来需要对5中特殊字符进行转移分别是&, <, >, “, ‘,参考这篇文章  Mybatis的XML文件sql特殊字符转义  

所以应该配置成如下(注意我多传递了另外一个参数serverTimezone=CTT),tomcat jndi启动便成功。

<?xml version="1.0" encoding="UTF-8"?>
<Context>

    <!-- These are the settings for Tomcat -->
    <Resource 
        name="jdbc/moikiitos"
        auth="Container"
        type="javax.sql.DataSource"
        username="root"
        password="root"
        driverClassName="com.mysql.cj.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/db_name?serverTimezone=CTT&amp;useUnicode=true&amp;characterEncoding=utf8"
        maxActive="8"
        maxIdle="4"
    />

</Context>