Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Help using Jakarta Commons Digester

Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I am using the Jakarta Commons Digester to facilitate XML-to-Object mapping in an init servlet.

I created the following:

1. myapp-rules.xml (containing rules for Digester)

2. attributes.xml (actual config file that I need to load & parse, and then place the objects in a data structure).

3. The POJO with setters and getters which holds the config file's info (after parsed through the init servlet).

4. A helper class which adds the POJOs to an ArrayList.

5. The init servlet which places myapp-rules.xml into the CLASSPATH and then loads the attributes.xml config file. This is where I think I need help on how to add it to the helper class.


Here's my web.xml file:


Here's the the Attributes POJO:

The helper class which I want to put the AttributeBean POJO inside an ArrayList:

Here's the init servlet (this is where I need help on how to add POJO to Helper class (array list):

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;
import org.apache.log4j.Logger;


public class XmlConfigInitServlet extends HttpServlet {

private AttributeBean attributeBeans;
private AttributeBeanHelper itemList;

public void init() throws ServletException {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("xml-config-file");
File xmlConfigFile = new File(prefix + file);
if (!xmlConfigFile.exists()) {
System.out.println("attributes.xml not found, "
+ xmlConfigFile.getAbsolutePath());
try {

// Configure Digester from XML ruleset
URL rules = getClass().getResource("./attribute-rules.xml");
Digester digester = DigesterLoader.createDigester(rules);

// Push empty List onto Digester's Stack
//List attributes = new ArrayList();

itemList = new AttributeBeanHelper();

// Parse the XML document
InputStream input = new FileInputStream(xmlConfigFile);

Logger.getLogger(this.getClass()).warn("After parsing the digester.");

} catch (Exception ex) {

For some odd reason, when my program tries to call the following XmlConfigInitServlet.itemList.addTypes(attributeBeans); I get the following exception:

Does anyone have any suggestions or tips on what I am doing wrong?


Legend has it that if you rub the right tiny ad, a genie comes out.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic