[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

chat application

Hi,

I need to implement online chat in my web application?
Please suggest some example or approach ?
0
Rocking
Asked:
Rocking
  • 3
  • 2
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now