homemy accounthelp

Wireless Java
JUG Utilities
Reference and Tutorials
Games and Entertainment
Techshowcase Downloads
Business Code
Unsorted Code


Chat Servlet 1.43

Title: Chat Servlet 1.43

Date Submitted: 4-16-2001

Date Modified: 4-16-2001


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

Usage notes

the usage is: http://your_host/servlet/ChatServlet?config_file Runs the chat and uses the mentioned file as a configuration file. Each chat (room) will be identified by the name of own configuration file. Configuration file is a text file, each line describes one parameter in the form of param=value Empty lines and lines begins with # or // are ignored. Current version supports the following list of parameters: # messages keeped on the screen (default value is 60) messages=50 # frames size. 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 # 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 # title. Default value is 'Coldjava chat' title=My chat # logout policy. Default value 1 means full chat logout. 2 keeps messages screen active. logout=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 and output # parameters. Default value is ISO-8859-1. encoding=Cp1251 # 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 administator. If you set this parameter user with such name # will be able to remove other users from chat admin=your_login_name Note: 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 full name for setting config file location: ChatServlet?/home/users/my_file (or ChatServlet?c:usersmy_file) 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 initial screen at all. Just incorporate such form into your HTML (JSP) page. JSP integration You may use ChatInfoBean for gettting information about existing 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="ChatInfoBean" %> <jsp:useBean id="Chat" class="ChatInfoBean" scope="page" /> <% int first_room=Chat.getUsersCount("/spacer.gif"); int second_room=Chat.getUsersCount("/spacer.gif"); %> <br>First room: <%= first_room %> users <br>Second room: <% =second_room %> users <p> They are in the first_room: <% Vector v=Chat.getUsersList("/spacer.gif"); int j=0; while (/spacer.gif)) out.println("<br>User:"+v.elementAt(/spacer.gif)+" Email:"+v.elementAt(/spacer.gif)); j+=2; {} %> What is new in 1.43: - workarounds for WebSphere-OS/390 bugs What is new in 1.42: - logout procedure fixed What is new in 1.41: - performance issue - WAP/WML support improvements What is new in 1.40: - improved support for log files What is new in 1.39: - DHTML support - new parameters (frames, maxlogin) What is new in 1.38: - new parameters (bgimage, offset) What is new in 1.37: - JSP integration What is new in 1.36: - new parameters (/spacer.gif) What is new in 1.35: - some bugs with old versions of Netscape fixed - WAP/WML support improvement

URL:: http://coldjava.hypermart.net/servlets/chatfaq.htm

Downloads: 664

Dec-:02:39 AM

Good servlet. Easy to use. No configuration. Does the job. Is there any way to get the source code for this? The URL (/spacer.gif) does not work.
from young92

Aug-:54:19 AM

ZIP broken? - Cannot Unzip!
from jordans

Not a member? register

Already registered?
Remember me

Forgot your password?