这个xml是否为context.xml很好地形成了?

时间:2012-03-30 05:56:17

标签: mysql xml netbeans

我正在研究Murach的Java servlet和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>

1 个答案:

答案 0 :(得分:3)

您正在立即关闭Context标记。删除&gt;。之前的/。

<?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>