Chat servlet 2.3

This Java servlet implements chat rooms. It is a pure HTML implementation, so, this chat is free from any firewall's restrictions. Also this chat supports WAP/WML and mobile users with legacy phones can join your chat's community too.

How to use it:

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

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


c) define a mapping for ChatServlet servlet in your web.xml file.


For each your chat (chat room) you must provide a configuration file describes how to use this chat as well as various interface settings. You can use ChatServlet in two forms.

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


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


and use servlet in this form:


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:

# messages per one screen (default value is 60)

# how to output messages. 1 (default value) - latest message is on the top
# 2 - latest message is on the bottom

# frames size. Describes how to split screen between main and control frames.
# Default value is 75%,25%

# border between input/output frames (default value is 1)

# view chat without login: 1 - yes, 0 - no (default value is 1)
# if view=1 you can see messages without logging into chat

# login frame name. You can run Chat in the separate frame.
# By default it is _top

# Your own login dialog. You can set your own
# html file for login dialog (first screen).
# See below how to write such file

# top (main) frame background (default value is #FFFFFF)

# bottom (control) frame background (default value is #FFFFFF)

# font color for control frame and login dialog (default value is #000000)

# You may set your own colors for hyperlinks (link,vlink and alink)
# By default chat will use current browser's settings

# font colors for hyperlinks in the main frame: link1,vlink1,alink1

# font colors for hyperlinks in the control frame: link2,vlink2,alink2

# background image for main frame (there is no image by default)

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

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

# DHTML support. Deploy DHTML features for chat's functionality.
# Default value is 0 (do not use DHTML). For modern browsers
# you may set dhtml=1 and avoid screen blinking.

# size for input field. Default value is 60.

# max. length for posted messages. Default value is 255

# max. length for user name. Default value is 20

# refresh time for main frame (in seconds).
# Default value is 20

# inactivity time in seconds (default value is 600)
# close user's session after that time in case of inactivity

# You may set maximum amount of connected users for your chat room.
# By default chat supports unlimited set of connections

# show host/ip info for users (default value is 0 - do not show)

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

# log files (no logs by default)
# Remark: log files will be filled at the  time when amount of messages
# reach the given restriction (see 'messages'). Chat will create one
# log file per day. File name for the each log is ddmmyyyy.htm (e.g. log
# file for Dec 07 2000 will be 07122000.htm).

# black list. You may set a list of IP addresses you need to prevent
# from login to this chat. This parameter describes a text file (you may
# use the full path for example) where you will keep a comma or space
# separated list of IP's. You may use submasks here. E.g.:
#, 192.168.2.*

# title. Default value is 'Coldbeans chat'
title=My chat

# logout policy. Default value 1 means full chat logout. 2 keeps messages screen active.

# logout button. Default value 1 - show logout button, 0 - do not show

# logo. You can add your own logo for the initial page.
# (in case you are using build-in login dialog).
# File you set here can have any html code.

# Localization support.

# You can set encoding for input parameters.
# Default value is ISO-8859-1. You have to do
# that on some containers for correct support.

# 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:

# translation. You may provide your own text file with labels
# used in forms. So you may translate them from English to
# your language for example. See below how to create such file

# You can run chat in the 1-1 chat mode. So each participant will be able to
# talk only with the specified user. E.g. teacher - students. For doing this
# set the login name for this selected user. Parameter name is master.

# Chat administrator. If you set this parameter user with such name
# will be able to remove other users from chat

# Unique names. If this parameter is 1 than duplicate login names
# will be disabled. Default value is 0

# URL for redirection in case of no HttpSession or no ChatUserName attribute in session.


1. Chat's configuration file can be saved anywhere on your server. E.g. if you are using ChatServlet?config line we assume this file is saved under the root directory of servletrunner. But you can of course always use the full name for setting config file location: ChatServlet?/home/users/my_file (or ChatServlet?c:\users\my_file) or you may use a full path relatively to your root: ChatServlet?/data/config.txt

2. Evaluation version displays extra © messages

Initial dialog (login dialog).

You can set your own html file for the initial screen. This file must have a form submitted login name, e-mail and foreground color to ChatServlet. So in the minimal configuration file can have just one form:

<form method="post" action="http://your_host/servlet/ChatServlet?your_config">
Name:<input type="TEXT" name="name"><br>
E-mail:<input type="TEXT" name="mail"><br>
Color:<input type="TEXT" name="color"><br>
<input type="Submit" value="Login">

Fields names are:

name - for user name
mail - for e-mail address
color - for foreground color

you can run Chat in the selected frame (iframe). Just set a target parameter for the form:
<form method="post" action="http://your_host/servlet/ChatServlet?your_config" target="your_frame">

You can set also default values for input parameters. E.g. only user name is required:

<form method="post" action="http://your_host/servlet/ChatServlet?your_config">
Name:<input type="TEXT" name="name"><br>
E-mail:<input type="hidden" name="mail" value=""><br>
Color:<input type="hidden" name="color" value="#000000"><br>
<input type="Submit" value="Login">

And you can skip default initial screen at all. Just incorporate such form into your HTML (JSP) page.

You can automatically add users to chat using data from HttpSessions. Just save in session user's name, user's email (optional) and selected color. Names for attributes in session scope are:

ChatUserName - for user name
ChatUserEmail - for e-mail address
ChatUserColor - for foreground color

This option lets you authorize users in your own application and reuse customer's data in the chat. Also you can prohibit access to chat for users with no ChatUserName attribute in sessions. Just describe in chat's config file parameter nosessionredirtect. So, you will be able to redirect non-authorized users to your own login page.


It is a text file. Empty lines and any line starts with # or // are ignored. Each line describes some replacement for default label in the form of:


Default labels are: User, Mail, Host, Address, To, Logout, Refresh, Log, Users, Send, All

For example:

Users=Who is online

JSP integration

You may use ChatInfoBean for getting the information about created chat rooms. Bean supports two methods:
int getUsersCount(String chatUrl)
Vector getUsersList(String chatUrl)

getUsersCount() lets you detect how many users are online and getUsersList() returns a Vector from pairs: <user_name, e-mail_address>


<%@ page language="java" import="" %>
<jsp:useBean id="Chat" class="ChatInfoBean" scope="page" />
   int first_room=Chat.getUsersCount("http://your_host/servlet/ChatServlet?first_room_config");
   int second_room=Chat.getUsersCount("http://your_host/servlet/ChatServlet?second_room_config");
<br>First room: <%= first_room %> users
<br>Second room: <% =second_room %> users
<p> They are in the first_room:
   Vector v=Chat.getUsersList("http://yourhost/servlet/ChatServlet?first_room_config");

   int j=0;
   while (j<v.size())
      out.println("<br>User:"+v.elementAt(j)+" Email:"+v.elementAt(j+1));

    Check out chat's FAQ also.

    For downloading:   chatPackage.jar  
    Sample of configuration file: chatconf

 © Coldbeans Software     Comments?

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


Also in JSOS: