Trivia servlet 1.3

    It is a Java servlet allows you to implement Trivia games or any test suite on your mobile phone with WAP support. Servlet reads XML-data file with the description of your test and generates on the fly an appropriate code for WML.

How to use it:

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

b) define servlet in your web.xml file.
 


    <servlet>
     <servlet-name>Trivia</servlet-name>
     <servlet-class>com.jsos.trivia.Trivia</servlet-class>
    </servlet>

define a mapping:
 


    <servlet-mapping>
     <servlet-name>Trivia</servlet-name>
     <url-pattern>/servlet/Trivia</url-pattern>
    </servlet-mapping>

You can use Trivia in two forms.

a) pass configuration file as a parameter. E.g.:
 


http://your_host/servlet/Trivia?your_xml_file

b) define your XML file as an initial parameter for servlet (parameter name is config):
 


    <servlet>
     <servlet-name>Trivia</servlet-name>
     <servlet-class>com.jsos.trivia.Trivia</servlet-class>
     <init-param>
      <param-name>config</param-name>
      <param-value>path_to_your_xml_file</param-value>
     </init-param>
    </servlet>

and use servlet in this form:
 

http://your_host/servlet/Trivia

XML file must define the following elements:

Trivia => (title, timeout, +question)

title - defines title for your game/test
timeout - defines timeout for individual questions (in seconds).

question => (ask, +option)

ask - defines the question
option - defines an alternative for this question. At least one of defined options must have an attribute correct with the value true or yes. This attribute marks the correct answer.

For example:
 


<trivia>

<title>Test</title>
<timeout>300</timeout>
<question>

<ask>What is a Java?</ask>
<option correct="yes">Programming language</option>
<option>Tea</option>
<option>Yet another buzzword</option>
</question>

<question>
<ask>What is a Coldbeans?</ask>
<option>Cold tea</option>
<option correct="true">Software start-up</option>
<option>Yet another buzzword</option>
</question>

</trivia>

Notes:

1. Servlet uses JAXP for parsing XML files.

2. Data file can be saved anywhere on your server. E.g. if you are using Trivia?data.xml we assume this file (data.xml) is saved under the root (docBase) directory of your servletrunner. But you can of course always use the full path for setting data file location. E.g. some like this: Trivia?/home/users/my_file (or Trivia?c:\users\my_file)

    For downloading: 

    Servlet:  triviaPackage.jar   
    Sample of xml file:  trivia.xml
 

  © Coldbeans     Comments?

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