I am using netbeans 6.9.1 with Glassfish 3 to create a web application consisting of a handful of servlets. I need to store a value in the config file for the database connection string.
From what I could find, this is done using the web.xm开发者_C百科l file (sun-web.xml being what is auto-generated):
<context-param>
<param-name>connectionString</param-name>
<param-value>connection string value in here</param-value>
and subsequently read in during servlet init() using
String conString = context.getInitParameter("connectionString");
However, when netbeans deploys the application I get the following error
SEVERE: DPL8007: Invalid Deployment Descriptors element param-name value connectionString SEVERE: DPL8007: Invalid Deployment Descriptors element param-value valu
Any idea what I am doing wrong here? Here is the full contents of the file:
<?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>
Thanks in advance.
I don't see <context-param>
in the sun-web.xml
DTD. So I guess you are not supposed to do this there. Place this in the regular web.xml
, it will work there.
Here are two more options, you can include it in your sun-resources.xml, or you can do it through the GlassFish DAS console.
Netbeans lets you create the sun-resources.xml through a wizard. You select it from New File -> GlassFish -> JDBC Resource. This is what the file looks like:
<?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>
精彩评论