News servlet 2.4

Yet another implementation of remote publishing. This is a Java servlets based implementation of news forum or blog. Forum is a collection of messages. Each message has got short announce (subject) and body. News servlet supports WAP/WML also. So you may use this servlet in your portal for example as a common source of news information for desktop and mobile clients.

NewsServlet supports file based persistence - your data will be saved in the flat file (files) or database based persistence. See below how to define this option.

How to use it:

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

b) define NewsServlet in your web.xml file:


c) define a mapping:


For each your forum you must provide a configuration file describes how to save messages as well as various interface settings. You can use NewsServlet in two forms.

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


2) define your configuration file as an initial parameter for servlet (parameter name is config):


and use servlet in this form: http://your_host/servlet/NewsServlet

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 persistence
# base directory, this parameter must be set in case of
# file based persistence. Points to any existing directory
# on your server.

# JDBC settings. You must set this in case db-based persistence
# Options are: (JDBC driver, database URL) pair or JNDI datasource

# JDBC driver
# database URL

# JNDI name (instead of the above mentioned pair)

# Optional parameter: user name for JDBC connection.
# Optional parameter: password for JDBC connection.

# name of the table
# See below DDL description for this table

# how to show full message: call server or use client side functionality
# possible values are server (default value) or client

# Interface

# forum title (default value is Coldjava's news)
title=My news

# background (default value is #FFFFFF)

# foreground color (default value is #000000)

# foreground color for subjects (default value is #008000)

# foreground color for messages (default value is #000000)

#font size (by default is current browser's font)

#font face (by default is current browser's font)

# sort data:  0 - first to last, 1 - last to first  (default value is 1)

# refresh time in seconds (default value is 600)

# enable/disable post messages. By default this parameter is empty
# and posting is enabled for everyone.
# You can provide here a commas separated list of roles for users allowed
# to post data

# page size in messages (default value is 10)

# enable/disable html codes in messages. 1- enable, 0 - disable. (default value is 0)

# header. You can set here some file contains any html-code. This code will be
# outputted at the beginning of the each page. So you can set for example some banners or CSS styles.
# By default this value is empty

# footer. You can set here some file contains any html-code. This code will be
# outputted at the bottom of the each page. So you can set for example some banners.
# By default this value is empty

# admin password. Default value is welcome

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

More about database persistence

All data will be saved in the one table. Name of this table is included in your configuration file (table=your_table). So if you support several stores each of them has got own table (probably in the same database). Table must be created before the first use of servlet with the appropriate configuration file. Use your database admin tools for doing this. Here is a DDL statement for this table:

CREATE TABLE your_table_name (
Moment CHAR(14),

You must use the same names for columns but depends on your database you can change types for columns (Msg and Subject). These columns (domains) will keep text data for individual messages. You may decide to use TEXT for example. Check out your DB manual for supported SQL data types.

Domain Moment will keep time stamp for messages (in milliseconds). We used type CHAR just for compatibility with JDBC-ODBC bridges (where the usage of any another type is one big bug). You may also change types from CHAR to VARCHAR.

You can manage by your message store running the same servlet in the so called Administrative mode. Here you can for example delete your messages. Appropriate command is:
or for example for historical data (one day ago):

See above for admin settings in the configuration file.


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

2. Also the base directory for messages store can be created at the any place of your server (just check access rights).

3. You can use the same servlet for access to the history data. For example one day ago data:

two days ago:

etc.  Or you can set the date directly (date format is yyyymmdd. E.g. June 05 2000 is 20000605):

4. For database persistence make sure you add your JDBC driver to CLASSPATH.

5. Evaluation version lets you see the first two pages only.

    For downloading:   newsPackage.jar

    Sample of config file: newsconf

 ©  Coldbeans     Comments?

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