Java Chat Application using JSP and ServletsBy: Sukhwinder Singh
|
DescriptionThis 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:
|
RequirementsThis 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. |
NoteThis 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. |
DownloadBefore 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. |
ConfigurationYou 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 chat.properties 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.
To delete rooms you have to manually edit WEB-INF/chat.properties file in chat.war or if application has been deployed then in the WEB-INF/chat.properties file present in the deployed directory (e.g <server deployment directory>/chat/WEB-INF/chat.properties). |
Contact InformationContact 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 (ssruprai@hotmail.com) |
Back to Top | Web Designing and development | JSP Chat Application Code | Compiling PHP Article | Freelance Web Developer | Freelance PHP Programmer
21/11/2024 06:57