Forum servlet 3.0


This is a Java servlet implements messages forum (or guestbook). Forum supports WAP/WML also so it can be used for your mobile users too. You may use this servlet for example as a guestbook, as a discussion thread, as a place for news/announces in your Intranet etc.

Forum 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 forumPackage.jar into your WEB-INF/lib directory.

b) define servlets in your web.xml file. There are two servlets: ForumServlet for forum itself and AdminForumServlet for administration:
 


    <servlet>
     <servlet-name>Forum</servlet-name>
     <servlet-class>com.jsos.forum.ForumServlet</servlet-class>
    </servlet>

    <servlet>
     <servlet-name>AdminForum</servlet-name>
     <servlet-class>com.jsos.forum.AdminForumServlet</servlet-class>
    </servlet>

define a mapping:
 


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

    <servlet-mapping>
     <servlet-name>AdminForum</servlet-name>
     <url-pattern>/servlet/AdminForum</url-pattern>
    </servlet-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 ForumServlet (or AdminForumServlet) in two forms.

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


http://your_host/servlet/Forum?config_file

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


    <servlet>
     <servlet-name>Forum</servlet-name>
     <servlet-class>com.jsos.forum.ForumServlet</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: http://your_host/servlet/Forum

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:

# Persistence

# base directory, this parameter must be set
# in case of file based persistence
dir=your_directory

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

# JDBC driver
driver=your_jdbc_driver
# database URL
url=your_db_url

# JNDI name (instead of the above mentioned pair)
jndiname=your_data_source

# Optional parameter: user name for JDBC connection.
user=db_user
# Optional parameter: password for JDBC connection.
password=db_user's_password

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

# Interface

# forum title (default value is Coldbeans forum)
title=My Forum

# style. Describes an URI for your CSS style file. By default is empty. E.g.:
style=/css/mystyle.css

# background (default value is #FFFFFF)
bgcolor=your_color

# you can set also different backgrounds for odd and even messages
# By default they are #FFFFFF.

# odd messages
oddbgcolor=your_color

# even messages
evenbgcolor=your_color

# background for titles (default value is #D8CEC0)
bgcolor1=your_color1

# you can set also different backgrounds for odd and even titles
# By default they are #D8CEC0.

# odd titles
oddbgcolor1=your_color

# even titles
evenbgcolor1=your_color

# foreground color (default value is #000000)
fgcolor=your_color

# you can set also different foreground color for odd and even messages
# By default they are #000000.

# odd messages
oddfgcolor=your_color

# even messages
evenfgcolor=your_color

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

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

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

# Date format. By default board will use full date.
# You may set here your own format for date. E.g.:
date=dd/MM/yyyy hh:mm

# offset. By default forum will use server's time (offset=0). You can
# set here time offset (+hours or -hours) if servlet is hosted in
# the another time zone.
offset=-3

# refresh time in the seconds (default 300)
refresh=your_time

# read forum: 1 - yes, 0 - no (default value is 1)
read=1

# ask/do not ask user's email. 1 - yes, 0 - no (default value is 1)
askemail=1

# ask/do not ask user's url. 1 - yes, 0 - no (default value is 1)
askurl=1

# enable/disable posting for 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
post=list_of_roles

# administrator's password. See Administrative mode below.
admin=your_password

# authorization flag (See Authorization section below)
authorized=attribute_name

# login page
login=your_page

# page size in messages (default value is 10)
page=8

# 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
header=path_to_your_file

# 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
footer=path_to_your_file

# Localization support.

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

# Charset. You may describe exclusively charset for output pages.
# By default servlet does not define charset exclusively.
# E.g. for Chinese you may do so:
charset=Big5
 

Administrative mode

You can manage by your message store if you run AdminForumServlet. Here you can for example delete your messages.

You can set administrator's password as a parameter in your configuration file. Parameter's name is admin. Default value for this password is welcome.

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 forums 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 (
Id CHAR(30) PRIMARY KEY,
Moment CHAR(14),
Author CHAR(80),
Email CHAR(80),
Url CHAR(80),
Msg LONG VARCHAR);

You must use the same names for columns but depends on your database you can change the type for the last column (Msg). This column (domain) 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. You may change types from CHAR to VARCHAR also.

Authorization

You may incorporate this forum into your portal where your users will be authorized. In order to prevent access to this forum from not authorized visitors you may use authorized parameter in config file. Servlet assumes that your authorization procedure will put some object into session (as a flag for authorized users). And name for this object should be described for Forum as a parameter authorized. Servlet checks session and if there are no such attribute than request will be forwarded or redirected to the page, described as a parameter login.

If login value starts with http than request will be redirected to that site. Otherwise servlet assumes a local resource and forwards request.

Interface translation

You can describe your own text file with text labels (static HTML/WML elements). This file should be defined through a parameter labels in your configuration file. It is a plain text file, each line describes one label in the form of:

label=new value

E.g.:

Author=Sender
Submit=Post message
etc.

Possible labels are:
Author, e-mail, http://, Reply, Submit, Clear, Pages, Date, Message, Action, Delete

CSS settings

You can add your own CSS file (see style parameter in config file) and set your own styles for interface's elements. For example:


/* textarea for input */

textarea
{
  width:225px;
  height:100px;
}

/* title */

h2
{
  font-size:50%;
}

/* input fields */

input[type=text]
{
  width:170px;
}

/* Submit button */

input[type=submit]
{
  width:90px;
}

/* Reset (clear) button */

input[type=reset]
{
  width:90px;
}

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 the file) means that your configuration file is saved under servletrunner's root (docBase) directory. But you can always use an absolute path to your config file as a parameter. E.g. some like this:
http://your_host/servlet/Forum?c:\myfiles\config.txt

Or you may use full path relatively to your root. E.g.:
http://your_host/servlet/Forum?/config.txt

2. Also the base directory for messages store can be created anywhere on your server (just check out access rights).

3. Evaluation version displays the first two pages only.

    For downloading:   forumPackage.jar

    Sample of config file: fconf

 ©  Coldbeans Software     Comments?

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

Also in JSOS: