Java Chat Application using JSP and Servlets

By: Sukhwinder Singh



This is a web based chat application and uses only JSP and Java Servlets. It doesn't use applets, activeX controls or database. It isn't a commercial application but a freeware, which shows how JSP and Java Servlets can be used. If you know Java and JSP you can also download source code of Java Classes and try to extend this application yourself.

Note: If you are looking for socket based chat application in Java that can be downloaded from here.

This chat application can be used for group discussion. You can download and use it in anyway you like but, please, don't remove the author information from any file. Here is a screen shot of a chat session:


Here are some of the things this chat application supports:

  • It supports rooms. Users can create their own rooms.

  • It allows users to find other logged in users.

  • It informs users in particular room when someone joins, leaves the room or logs out.

  • It allows users to store some personal information which can be viewed by others.

Back to Top


This application needs container with support for Servlet 2.3 and JSP 1.2 specification because it uses listeners which are available only in Servlet 2.3 specifications. Tomcat 4/5/5.5 and Resin 2.1 or greater, both support Servlet 2.3 spec.

It may work on Servlet 2.2 container but problem you'll face is, if a user doesn't log out manually then his object won't be removed from application ( ServletContext) object. When his session expires his session will be destroyed automatically but information stored in application object won't be destroyed and will remain there.

Back to Top


This application has been available for download since April, 2003 and no one has yet reported any problem with it.

Please don't ask author how to configure it in your Servlet container as it works out of the box in Tomcat and Resin. Developers can also download source code of Java classes (which can be easily extended) and try to fix bugs or extend and improve this application. After fixing bugs or extending this application you can send author the modified files so that he can update the application in future.

Author wrote this application because he wanted to know how web based chat applications work and to improve his knowledge of JSP and Servlets. He was not able to find some complete example of it on web. He read Professional Java Server Programming from wrox and it provided him a starting point. As author just wanted to show how chat applications work, there is minimal validation done on user input. Validation is done only when it may affect the application functionality as it is just a demonstration of author's work. For example, an email address user provides, is not validated. But validation can be easily added.

This application makes heavy use of ServletContext to store every object as no database is used. It is just plug and play kind of thing. So memory requirements may be high. Memory requirement will depend upon the number of users currently logged in.

It won't, but if this application crashes or harms your computer in any way, author won't be responsible for it.

Back to Top


Before downloading this application, you must read note above. As you have read, this application was written originally written in 2003. It has not been updated since then but it has been tested with latest Tomcat version, which is 8 at this time (Oct, 2014) and it still works without any problem. Download this zip file (261 kb). You could also download java source code, if you want to experiment yourself. After downloading this zip file extract its contents somewhere. In extracted files there will be a file named chat.war. Please note that .jsp and other files are inside that chat.war file, which is just a zip file. Copy this chat.war to your Servlet/JSP container's webapps directory. For Tomcat 4.1 / 5.0 / 5.5 / 8.0 and Resin 2.1 there is a sub-directory named webapps. Copy this chat.war file to this webapps directory and start your container or server. The servlet container will extract contents of this chat.war file and deploy it. If you look inside webapps directory you'll see a newly created directory (/webapps/chat) with contents of the chat.war file. Look inside that folder to see what is there. It'll have documentation as well as jsp and other files. Then you can access this application by using a URL like http://localhost:8080/chat/. Replace localhost with name of your server. If your container/server is using some other port, then change port number from 8080 to that port.

Developers  can also download source code of Java classes.

Please don't contact author for any support as this application was done way back and he has been doing web development using PHP since then. You won't get any reply regarding this chat application.

Back to Top


You can configure this application by changing some parameters is WEB-INF/web.xml file in chat.war. To edit this file before deploying you have to extract contents of this chat.war file. In the files extracted there will be a directory named WEB-INF. In this directory there will be a file named web.xml. In this web.xml file you can change the options given in the table below. After making the changes you have to recreate the chat.war file again. You can create this war file using any zip utility like JDK's jar or WinZip. After creating the zip file just change its extension from zip to war. There is also a file named in WEB-INF directory, which stores the name of chat rooms and their description. At server startup this file is read. If this file is missing then error is displayed in console and application won't work. There are few initialization parameters which can be changed. Comments have been added to this web.xml file about the settings you can change. There are six parameters you can change.

Parameter Name Parameter Value Description
chatpropertyfile Any file name without any path. This file must be stored inside WEB-INF subdirectory of war file. You can change the name of the file which is used to store room names and description. Author recommends that you don't change this parameter. 
saveRooms true / false The value of saveRooms can be set to true or false. If true then all new rooms added by users will be saved in files. Default is false.
adminEmail Any valid email address. Provide an e-mail address of the administrator of this application. This email address is displayed when any error occurs in application. On error page this email is displayed for contacting the admin.
sessionTimeout no. of minutes Add time in minutes after which user's session will be expired.
If user doesn't make any request after provided minutes he will be automatically logged out and his information will be destroyed.
Default is 30 minutes
refreshAfter no. of seconds Time in seconds after which user's browser window will automatically refresh to display
new messages.
Default is 10 seconds.
maxNoOfMessages any number Maximum Number of messages that are stored in a list which is used to store all messages
in a room. After this limit is reached older messages are removed. Set this to some reasonable value depending upon the no. of active users you expect.
Default is 25.

To delete rooms you have to manually edit WEB-INF/ file in chat.war or if application has been deployed then in the WEB-INF/ file present in the deployed directory (e.g <server deployment directory>/chat/WEB-INF/

Back to Top


Contact Information

Contact author for any freelancing web development work like Content Management Systems, E-commerce applications or other web development work in PHP. If you liked the software and want to support author, please visit some of the google sponsers.

Sukhwinder Singh (

Back to Top | JSP Chat Application Code | Compiling PHP Article | Web Designing and development | Freelance Web Developer | Freelance PHP Programmer
20/06/2024 09:54