sun-web.xml中的Context Param问题

时间:2010-12-21 15:02:47

标签: java servlets

我正在使用带有Glassfish 3的netbeans 6.9.1创建一个由少量servlet组成的Web应用程序。 我需要在数据库连接字符串的配置文件中存储一个值。

根据我的发现,这是使用web.xml文件(sun-web.xml是自动生成的)完成的:

<context-param>
<param-name>connectionString</param-name>
<param-value>connection string value in here</param-value>

然后使用

在servlet init()期间读入
String conString = context.getInitParameter("connectionString");

但是,当netbeans部署应用程序时,我收到以下错误

SEVERE: DPL8007: Invalid Deployment Descriptors element param-name value connectionString SEVERE: DPL8007: Invalid Deployment Descriptors element param-value valu

知道我在这里做错了吗?以下是该文件的完整内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app error-url="">
<context-param>
<param-name>connectionString</param-name>
<param-value>Con value</param-value>
 </context-param> 
<context-root>/FQEX</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
  </jsp-config>
</sun-web-app>

提前致谢。

2 个答案:

答案 0 :(得分:1)

我在<context-param> DTD中看不到sun-web.xml。所以我猜你不应该那样做。将其放在常规web.xml中,它将在那里工作。

答案 1 :(得分:0)

以下是另外两个选项,您可以将它包含在sun-resources.xml中,也可以通过GlassFish DAS控制台进行。

Netbeans允许您通过向导创建sun-resources.xml。您可以从新文件中选择它 - &gt; GlassFish - &gt; JDBC资源。这就是文件的样子:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/something" object-type="user" pool-name="something_pool">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="5" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="table" validation-table-name="something_pool.sometable" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="120" is-connection-validation-required="true" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="100" max-wait-time-in-millis="60000" name="something_pool" non-transactional-connections="false" pool-resize-quantity="8" res-type="javax.sql.DataSource" statement-timeout-in-seconds="180" steady-pool-size="32" validate-atmost-once-period-in-seconds="5" wrap-jdbc-objects="false">
<property name="URL" value="jdbc:mysql://localhost:3306/something"/>
<property name="User" value="root"/>
<property name="Password" value="admin"/>
</jdbc-connection-pool>
</resources>