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)
# how to output messages. 1 (default value) - latest message is on the top
# frames size. Describes how to split screen between main and control frames.
# border between input/output frames (default value is 1)
# view chat without login: 1 - yes, 0 - no (default value is 1)
# login frame name. You can run Chat in the separate frame.
# Your own login dialog. You can set your own
# 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)
# 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.
# 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).
# inactivity time in seconds (default value is 600)
# You may set maximum amount of connected users for your chat room.
# 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
# log files (no logs by default)
# black list. You may set a list of IP addresses you need to prevent
# title. Default value is 'Coldbeans 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.
# Localization support. # You can set encoding for input parameters.
# Charset. You may describe exclusively charset for output pages.
# translation. You may provide your own text file with labels
# You can run chat in the 1-1 chat mode. So each participant will be
able to
# Chat administrator. If you set this parameter user with such name
# Unique names. If this parameter is 1 than duplicate login names
# URL for redirection in case of no HttpSession or no ChatUserName attribute in session.
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
you can run Chat in the selected frame (iframe). Just set a target parameter
for the form:
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
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:
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
© Coldbeans Software Comments? See also JSOS - the largest collection of servlets and filters. |
Also in JSOS:
|