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.
 


    <servlet>
     <servlet-name>ChatServlet</servlet-name>
     <servlet-class>com.jsos.chat.ChatServlet</servlet-class>
    </servlet>

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


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

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

http://your_host/servlet/ChatServlet?config_file

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


    <servlet>
     <servlet-name>ChatServlet</servlet-name>
     <servlet-class>com.jsos.chat.ChatServlet</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/ChatServlet

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:

# messages per one screen (default value is 60)
messages=50

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

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

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

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

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

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

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

# bottom (control) frame background (default value is #FFFFFF)
bgcolor2=#FFFF00

# font color for control frame and login dialog (default value is #000000)
fgcolor=#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
link1=#FFFFFF

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

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

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

# font face (by default is current browser's font settings)
face=Arial,Times

# 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.
dhtml=1

# size for input field. Default value is 60.
input=50

# max. length for posted messages. Default value is 255
maxlength=80

# max. length for user name. Default value is 20
maxlogin=25

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

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

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

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

# 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.
offset=-3

# 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).
log=any_existing_directory_for_log_files

# 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.1.2, 192.168.2.*
blacklist=your_data_file

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

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

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

# 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.
logo=path_to_your_file

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

# 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
translation=path_to_your_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.
master=your_login_name

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

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

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

Notes:

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:
 


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

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:
 


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

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.

Translation.

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_label=your_replacement

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

For example:
 


Refresh=Update
Log=Protocol
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>

E.g.:
 


<%@ page language="java" import="com.jsos.chat.ChatInfoBean" %>
<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));
      j+=2;
   }
%>

    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: