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.
 

    <servlet>
     <servlet-name>SurveyXMLServlet</servlet-name>
     <servlet-class>com.jsos.survey.SurveyXMLServlet</servlet-class>
    </servlet>

c) define a mapping:
 


<servlet-mapping>
   <servlet-name>SurveyXMLServlet</servlet-name>
   <url-pattern>/servlet/SurveyXMLServlet</url-pattern>
</servlet-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:
 

http://your_host/servlet/SurveyXMLServlet?configuration_file

E.g.:
 

<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">
</form>

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:
 

    <servlet>
     <servlet-name>SurveyXMLServlet</servlet-name>
     <servlet-class>com.jsos.survey.SurveyXMLServlet</servlet-class>
     <init-param>
      <param-name>config</param-name>
      <param-value>path_to_your_configuration_file</param-value>
     </init-param>
    </servlet>

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">
</form>

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

  parameter=value

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

Current version supports the following list of parameters:

# data file. This parameter is mandatory
xml=path_to_your_file

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

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

# dtd. Document type definition file
dtd=your_dtd_file

# xsl. Describes your own stylesheet
xsl=your_xsl_file

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

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:


after=http://www.acme.com?$posted_parameter
error=error_page.jsp?param=$hidden_field

Notes:

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:
http://your_host/servlet/SurveyXMLServlet?c:\myfiles\config.txt

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: