SurveyXMLServlet v. 1.9

This Java servlet collects data from any html form and saves them in xml-format.

You must just set this servlet as an action parameter for your form. Servlet reads posted data and saves them in xml file.

How to use it:

a) copy surveyPackage.jar into your WEB-INF/lib directory.

b) define SurveyXMLServlet servlet in your web.xml file.


c) define a mapping:


In order to use this servlet you have to provide a configuration file. This file describes how to save data and what to do after that. There are two forms of usage:

a) pass configuration file as a parameter:



<form method="post" action="http://your_host/servlet/SurveyXMLServlet?xmlconfig.txt">
Enter your name   <input type="Text" name="Name">
Enter your e-mail  <input type="Text" name="*Email">
<input type="Submit" name="Submit" Value="Submit">

b) describe configuration file as an initial parameter for servlet (parameter name is config). So in your web.xml file you may have some like this:


and use servlet in this form:

<form method="post" action="http://your_host/servlet/SurveyXMLServlet">
Enter your name   <input type="Text" name="Name">
Enter your e-mail  <input type="Text" name="*Email">
<input type="Submit" name="Submit" Value="Submit">

Servlet provides server side validation for posted data. All fields those names begins with * are mandatory.

By default servlet uses the following DTD:

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT records (record+)>

you can define your own DTD file in servlet's config.

Configuration file is a text file, each line describes one parameter in the form of


Empty lines and any line starts with # or // are ignored.

Current version supports the following list of parameters:

# data file. This parameter is mandatory

# error page. Page for redirection in case some error occurs.

# 'after' page. Page for redirection after data saving

# dtd. Document type definition file

# xsl. Describes your own stylesheet

# localization support. You can set character encoding for input parameters
# here. Default value is ISO-8859-1

Post-processing customization

You may customize after-saving and error redirection pages with data submitted in the request. When you describe after (or error) parameter in your configuration file you may use templates like $some_name. Servlet assumes that some_name is a parameter in posted request and $some_name will be replaced with encoded value of this parameter. So, in your config file you may have some like this:



1. You can save configuration file anywhere on your server. Just use the proper path for setting servlet's parameter. Short path (just a name of your file) means that your configuration file is saved under servletrunner's root directory. But you can always use some like this:

2. XML file can be created anywhere on your server (just check out access rights).

3. If after or error value starts with http than request will be redirected to that site after data saving. Otherwise servlet assumes a local resource and forwards request.

For downloading:

servlet: surveyPackage.jar

 © Coldbeans Software     Comments? 

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: