sun-web.xml中的Context Param问题

我正在使用带有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>
提前致谢。     
已邀请:
我没有在
sun-web.xml
DTD中看到
<context-param>
。所以我猜你不应该那样做。将它放在常规
web.xml
中,它将在那里工作。     
这里有两个选项,您可以将它包含在sun-resources.xml中,也可以通过GlassFish DAS控制台完成。 Netbeans允许您通过向导创建sun-resources.xml。您可以从New File - > GlassFish - > JDBC Resource中选择它。这是文件的样子:
<?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>
    

要回复问题请先登录注册