Reputation: 71
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<meta charset="utf-8">
<title>Chat</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function() {
$('#button').click(function() {
$.get('/backEnd', function(data) {
$("#textarea").html(data);
});
});
});
</script>
</head>
<body>
<label for="textarea">
<blockquote>
<ul>
<ul>
<li><strong>Session Progress</strong></li>
</ul>
</ul>
</blockquote>
</label>
<p>
<textarea name="textarea" cols="88" rows="33" id="textarea"></textarea>
</p>
<button id="button">Update</button>
<p> </p>
<p>
<label for="textarea2">
<ul>
<ul>
<li><strong>Session Message input</strong></li>
</ul>
</ul>
</label>
<textarea name="textarea2" cols="44" rows="11" id="textarea2"></textarea>
</p>
<p>
<input type="button" name="button" id="button" value="Send">
</p>
</body>
</html>
the above is the jsp for the chat page, the user should type text into textarea2 and accordingly it should appear in textarea1 if it was sent successfully, but how can i do this in order for 2 clients to talk with each other
Upvotes: 1
Views: 709
Reputation: 4081
You should have a servlet which has an action where the messages from both sides are posted. This servlet should hold those messsages in some kind of data structure. Now both conversation sides should poll a different action in certain time interval to check if new messages have appeared in this collection and update those text areas accordingly.
This is one of many many ways to implement your requirements.
Upvotes: 2