我正在研究 Murach 的 Java servlets 和 JSP,第 14 章关于连接到 MySQL,但我做不到。我正在使用 Netbeans 和 Tomcat。如果我尝试使用以下 context.xml 文件运行代码,则代码将不会运行。它说
[Fatal Error] :3:2: The markup in the document following the root element must
be well-formed.
/Users/user/NetBeansProjects/LearnYou/nbproject/build-impl.xml:724:3
Deployment error: Tomcat configuration file /Users/user/NetBeansProjects/LearnYou/web/META-INF/context.xml seems to be broken. Please make sure it is parseable and valid.
如果我注释掉除第一行以外的所有内容,那么代码会运行但永远不会连接到 MySQL。
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/projectname"/>
<Resource
name="jdbc/ULearniversity" auth="Container"
maxActive="100" maxIdle="50" maxWait="60000"
username="uName" password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyDataBase?autoReconnect=true"
logAbandoned="true" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource"
/>
</Context>
最佳答案
您将立即关闭 Context 标签。删除 > 之前的/。
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/projectname">
<Resource
name="jdbc/ULearniversity" auth="Container"
maxActive="100" maxIdle="50" maxWait="60000"
username="root" password="rootpassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyDataBase?autoReconnect=true"
logAbandoned="true" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource"
/>
</Context>
关于mysql - 这个 xml 是否适合 context.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9937690/