File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to implement Online Chat Application using simple jsp and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to implement Online Chat Application using simple jsp and servlets" Watch "How to implement Online Chat Application using simple jsp and servlets" New topic
Author

How to implement Online Chat Application using simple jsp and servlets

Snehitha Prasad
Ranch Hand

Joined: Jul 06, 2012
Posts: 32
Hi Guys,

I am new here and am hoping that you may be able to give me a few pointers.

I am writing a chat application in Java.

I have a client that connects to the server and sends over a username. The username is stored in the new thread instance. This way the server can distribute the chat name as well as the conversation text to all the clients

so everyone knows who is talking.

What approach should I take to achieve this?? What would be the most sensible way of doing it?

Till now what i did is i just create a Loginservlet,when the user login to the application using login.jsp page i store this username in a session and add this username into ArrayList object.
If somebody access this application from other system and logs in using another user name according myrequirement the list size is must be two.but still it is showing size as 1 only.

can somebody help me on this.how can i add all login users from different systems how can we add all the login usernames into this list object....

I am eagerly waiting for your reply.

Thanks in advance for your comments.

SNEHITHAPRASAD
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2712
    
    5

This would need Ajax also. Only Servlets and JSP won't suffice to make it close to real time.
Then there are two possible approaches from my view, one is the chatroom where everyone sees what every other user sends. Other is the personal chat option like GTalk.
First one would require less effort as all messages are simply broadcasted.


SCJP, SCWCD.
|Asking Good Questions|
Snehitha Prasad
Ranch Hand

Joined: Jul 06, 2012
Posts: 32
Hi Amit Ghorpade,

Thanks for your quick response.

Actually i did the first approach.I mean i implemented the first approach like everyone sees what every other user sends without using Ajax ,In this i use servlets and jsp. But i want how to implement one-to-one chatting. Can you please give some inputs to implement one-to-one chatting.

Thanks in Advance.

SNEHITHAPRASAD
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1966
    
    7

You mention storing the user login in a session variable. And sessions are user specific, every login has its own session. I may consider storing the user login in an application or context variable instead.

Yet another approach is to have a POJO as your so-called logged-in collection. As people log in you add his username to your POJO.

Thinking about it either approach makes this collection thing application level.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Snehitha Prasad
Ranch Hand

Joined: Jul 06, 2012
Posts: 32
Hi K.Tsang ,

Thanks for your replay.Can you please give me some inputs on how to implement one-to-one chating using servlets and jsp.

Thanks in advance,

SNEHITHAPRASAD
Bhoopendra Singh
Greenhorn

Joined: Feb 21, 2012
Posts: 3
Since session is specific to single user, storing signed in user details in session will not work. You need to store signed in users details in location which accessible from all live session. One of the option is application context. Other maybe some some external persistent storage.
Also, since this is a web based application, which approach is being used "Pull" or "Push" to show incoming chat message?
Juran Novarski
Greenhorn

Joined: Jan 03, 2013
Posts: 5
hello,

I'm also having a project a chat application with java.. I'm jus wondering that how to set up the connection between the client and the server? Does it have to set up lan connection?

can someone explain the processes invlove in this applicaton?

Thank you!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
JSPs probably don't figure much into it. It'd be HTML pages that use some JavaScript library (like jQuery) to pass JSON back and forth to the server.


Ping & DNS - updated with new look and Ping home screen widget
Juran Novarski
Greenhorn

Joined: Jan 03, 2013
Posts: 5
hmm..what i'm trying to say is that how can this be implemented through java? what are the processes?
Juran Novarski
Greenhorn

Joined: Jan 03, 2013
Posts: 5
How can the this application done by assigning a pc as the server and others as the client??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
You probably would use servlets on the server-side, and jQuery in the browser. If you aren't familiar with these technologies, start reading up on them.
Juran Novarski
Greenhorn

Joined: Jan 03, 2013
Posts: 5
Thanks for the quick reply

Me,and my team would like to make a desktop application of that. For he fact that we are still newbies, sutdents, i would just like to ask your kind knowledge on how can we set up the application by implementing as desktop application of chat. Do we have to set up the lan connection by testing our program?? How should we tes the server side? How about he client side? What are the necesary technologies to be used?
Sorry if I asked too much about this because I really don't know how to continue making without knowing what to do next.

Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
As I said, servlets on the server-side in a container such as Tomcat. Doesn't matter whether the client is a browser or a standalone app.

A Java desktop client would likely use a library like Apache Commons HttpClient (or maybe even just the java.net classes that deal with HTTP) to access the server.

It doesn't matter whether the clients and the server run on different machines, or for testing purposes all on the same machine - the clients just need to know the IP address and the port on which to connect to the server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to implement Online Chat Application using simple jsp and servlets
 
Similar Threads
Chat application implementation method?
URGENT!! chat applet
How can i Pass String in to Socket .....Urgent..urgent
Java chat application implementation method
JNDI and LDAP group operations