Chapter 7. Generation of the Servlet related files

To generate the Web descriptors, we need to create another XDoclet configuration, like we did for our EJB.

Procedure 7.1. XDoclet Web Configuration Creation

  1. Edit the project properties. Right-click on the project and select Properties.
  2. In the properties page, select XDoclet Configurations.
  3. Right-click in the top area to pop-up the menu and choose Add. Type Web in the dialog and click OK.

You have created a new generation configuration named Web.

Procedure 7.2. Webdoclet Configuration

  1. Select the Web configuration.

  2. In the lower-left area, right-click to popup the menu and choose Add Doclet.

  3. A list of available doclets will appear. Choose webdoclet and click OK.

  4. On the lower-right area, you see the properties of the ejbdoclet.

    1. Set the destDir property to src/WEB-INF.

Our configuration now contains a webdoclet that will produce files in the src/WEB-INF folder.

Procedure 7.3. Fileset Configuration

  1. In the lower-left area, right-click on webdoclet to popup the menu and choose Add.
  2. A list of available subtasks will appear. Choose fileset and click Ok.
  3. On the lower-right area, you see the properties of the fileset.
    1. Set the dir property to src.
    2. Uncheck excludes
    3. Set the includes property to **/*Servlet.java.

Our configuration now contains a webdoclet with a fileset that contains the src directory, and all files under it that end in Servlet.java.

Procedure 7.4. Deployment Descriptor Configuration

  • Add a new deploymentdescriptor subtask to the webdoclet (see above).
    1. Set the Servletspec property to 2.3.

All of the standard Web deployment descriptors will now be placed in the src/WEB-INF directory (property is inherited from webdoclet).

Procedure 7.5. JBoss Configuration

  • Add a new jbosswebxml subtask to the webdoclet (see above).
    1. Set the Version property to 3.0.

All of the JBoss-specific Web deployment descriptors will now be placed in the src/WEB-INF directory (property is inherited from webdoclet).

Click OK and the XDoclet configuration for the Tutorial will be saved. Once the configuration is saved, right-click on the Tutorial project and select Run XDoclet. The XDoclet generation will display its output in the console. The output should look like this:

After the generation, you should have a project that looks like this. Note that a WEB-INF folder has been created with the web deployment descriptors (both standard and jboss).

In order to run our servlet, we'll need to create an HTML page that passes it parameters.

Procedure 7.6. Creating the HTML Page

  1. Create a docroot folder under the root of the project.
  2. Create an empty file named index.html under the docroot folder.

The index.html file is intended to be the default page for the Web application and contains a form that will be posted to the Servlet.

The following content should be copied into the index.html file:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
      <title>
         Fibonacci Application
      </title>
   </head>
   <body>
      <h1>Fibonacci Form</h1>
      <form action="Compute" method="POST" >
         <table cellspacing="2" cellpadding="2" border="0">
            <tr>
               <td>
                  Limit :
               </td>
               <td>
                  <input type="text" name="limit" value="50">
               </td>
            </tr>
            <tr>
               <td>
                  <input type="submit" name="Compute" value="Compute">
               </td>
               <td>
                  <input type="Reset">
               </td>
            </tr>
         </table>
      </form>
   </body>
</html>