chat application

Hi,

I need to implement online chat in my web application?
Please suggest some example or approach ?
RockingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
You'll want to take a look at Node.js or SignalR.
0
rrzCommented:
Do you want something simple in JSP?
0
RockingAuthor Commented:
yes jsp and servlet
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

rrzCommented:
There are some already written. Look at
https://www.google.com/?gws_rd=ssl#q=jsp+chat+application   
But, if you want something really simple, we could write some code here. What are your requirements?
0
RockingAuthor Commented:
a simple program with user can do online chat with the administrator like that in experts exchange
0
rrzCommented:
I found time to start on this. I coded it the simplest way that I could think of doing it. There certainly is a lot more to do.  Right now, it is all on one page.  Later the chat can be in a separate window that refreshes  itself or uses AJAX. Later we can add a HttpSessionListener to remove invalid sessions from the map. Or the admin could remove old chats manually. Later we could use usernames for display. Maybe later we might think about thread safety if its a problem. Please copy, paste, and test.
<%@ page import="java.util.HashMap" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
  HashMap<String,String> map = (HashMap<String,String>)application.getAttribute("map");
  if(map == null){
                   map = new HashMap<String,String>();
				   application.setAttribute("map",map);
  }
  String id = session.getId();
  if(!map.containsKey(id))map.put(id,"Hello<br/>");
  String message = request.getParameter("m");
  String userId = request.getParameter("i");
  if(userId != null && !"".equals(userId.trim()))id = userId;
  if(message != null && !"".equals(message.trim())){
		String chat = map.get(id);
		chat += message + "<br/>";
		map.put(id,chat);
  }
%>
<c:if test='${param.ad == "password"}'>
	<c:forEach items="${map}" var="item">
		${item.key} = ${item.value} <br/>
	</c:forEach>
</c:if>
<c:if test='${param.ad != "password"}'>
	${map[pageContext.session.id]}
</c:if>
<html>
<head>
<title>Chat</title>
</head>
<body>
<form>
<c:if test='${param.ad == "password"}'>
  Admin, enter id you want to talk to<input type="text" name="i">
</c:if>
  Type message<input type="text" name="m">
  <input type="submit">
    If you are admin Enter admin password<input type="text" name="ad" value="${param.ad}">
</form>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.