Add and Modify XML

Create a new context.xml file, and modify the existing web.xml file.

Add context.xml

We provide the XML code that sets the configuration of the PUBS database. You must add the XML to your project.

  1. In the Project Explorer, expand JSPBookDemo > WebContent.
  2. Right-click META-INF; then select New > Other.
  3. Expand XML; then select XML File.
  4. Click Next.
  5. In the File name field, type context.xml; then click Finish.

    This opens the empty context.xml file in the file editor.

  6. Copy the following XML code and paste it into the context.xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- maxActive: Maximum number of database connections in pool. Make sure you
             configure your mysqld max_connections large enough to handle
             all of your db connections. Set to -1 for no limit.
           <!-- maxIdle: Maximum number of idle database connections to retain in pool.
             Set to -1 for no limit.  See also the DBCP documentation on this
             and the minEvictableIdleTimeMillis configuration parameter.
           <!-- maxWait: Maximum time to wait for a database connection to 
             become available in ms, in this example 10 seconds. 
             An Exception is thrown if this timeout is exceeded.  
             Set to -1 to wait indefinitely.
           <!-- username and password: username and password for the connection -->
           <!-- driverClassName: Class name for the JDBC driver -->
           <!-- url: The JDBC connection url for connecting to the database -->
           <Resource name="PUBS" auth="Container" type="javax.sql.DataSource"
                   maxActive="10" maxIdle="10" maxWait="10000"
                   username="SQLServerUserName" password="SQLServerPassword"

    Replacing SQLServerUserName and SQLServerPassword respectively with the user name and password required for SQL Server authentication

  7. Click File > Save to save the file.

Modify web.xml

The web.xml file requires modification to accommodate the SQL Server database.

  1. In the Project Explorer expand JSPBookDemo > WebContent > WEB-INF.
  2. Double-click web.xml to open it in the file editor.
  3. Replace the entire contents of the file with the following:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi=""
          <description>DB Connection</description>
  4. Click File > Save to save your changes.