Exercise

To practice working with XML, try the following two exercises; the first is relatively simple, but the second requires a little more effort.

  1. Extend the WebDDBuilder application to optionally read in an existing web.xml file and add the new <servlet> and <servlet-mapping> elements from the servlet class and URL pattern information provided on the command line.

    Hint: Most of the code is already in place. You will need to create another constructor to build the DOM tree from an existing DD whose filename is supplied as the last (optional) parameter on the command line. A simple web.xml file is provided in the Day16/solution/XML directory.

    TIP

    If your web.xml file has a non-local DTD specified in the DOCTYPE element (this will be the case if you are using a J2EE 1.3 or earlier web.xml file), you will require access to the Web for the parser to validate the XML.


  2. Enhance your solution to check for duplicate servlet names. The servlet name in a Web Application DD must be unique. Ensure that the program will not add the same servlet class twice by checking for duplicate servlet names before adding the new entry.

A solution is provided in the Day 16 solution directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.61