Hello,

I am making a chat application using JSP & Servlets.I have written the code for my one-to-one chat module which is not working fine.So please have a
look at this code to rectify the errors due to which i'm not getting the desired output.

This code is for sending the message to a particular user through my JSP page send121.jsp using the servlets.

Ii've used the concept of XMLHttpRequest in this code.the code for "send121.jsp" is as follows:

Code:
<%@ page errorPage="error.jsp" import="java.util.Set,java.util.ArrayList,java.util.Iterator,java.util.Map,com.chat.*"%>
<%
	String nickname = (String)session.getAttribute("nickname");
	ArrayList messageList=null;
	String mess = null;
	String msg = null;

if(nickname != null)
{
			
%>

<HTML>
<HEAD>

<script language="javascript">

var theURL = "<%=request.getContextPath()%>/servlet/oto?message=";
var http = getHTTPObject(); 

function handleHttpResponse() {
  if (http.readyState == 4) 
  {
 
  }
}

function callServlet(formElement) {
  var searchQuery = document.forms[0].elements[formElement].value;
  http.open("GET", theURL + escape(searchQuery), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function getHTTPObject() {
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
     try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
        xmlhttp = false;
     }
  }

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }

  return xmlhttp;
}

</script>
</HEAD>

<BODY onLoad="document.msg.messagebox.focus();" bgcolor="#FFFFFF">
<div align="center">

<center>
	<table border=0 width=640>
        <tr>
	<td>
	    < table border=0 bgcolor=white width=100% class=content cellpadding=8>
			<form name="send" action="#" onSubmit="return false;">
          		<tr> 
            		<td align="right"> <b>  Send: </b> </td>
            		<td align="left" >
                	    <input type=text name=txtfield size="40" maxlength="60" onBlur="callServlet(1);" >
					</td>
          		</tr>
			
			<tr> 
            		<td valign="top" align="right"> <b> Messages: </b> </td>
            		<td align="left" >
					<TEXTAREA cols="30" rows="5" wrap="VIRTUAL" name="comment"><%//=msg%></TEXTAREA> 
					</td>		
				</tr>	
		       </form>
        </table>
<%
	messageList = (ArrayList)request.getAttribute("message");
	if(messageList!=null)
        {
	   for(int i = 0; i <messageList.size() ; i++)
           {
	       mess = (String) messageList.get(i);
	      msg = nickname + "->" + mess;
	      System.out.println(msg);
	   }
							
        }
						
%>
		


</td>
</tr>
</table>
</center>


</BODY>
</HTML>
<% 
				
	}
			
%>
When the onBlur event is executed the callservlet()Function of javascript is called, through which my OnetoOneServlet .java gets the message parameter,that message parameter's value i'm storing in an ArrayList using a plain old java class namely OnetoOne.java.

the code for both the servlet & plain java class i'm providing below.

OnetoOneServlet.java

Code:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.chat.OnetoOne;

public class OnetoOneServlet extends HttpServlet
{
	String nickname;
	HttpSession session;
	String msg;

	public void doGet(HttpServletRequest req, HttpServletResponse res)
	        throws ServletException, IOException
    {

	session = req.getSession();
	nickname = (String)session.getAttribute("nickname");

	msg = req.getParameter("message");

	if (nickname != null && nickname.length() > 0)
	{
        	OnetoOne oto = new OnetoOne();
		List result = oto.getMessages(msg);
        	req.setAttribute("message",result);
getServletContext().getRequestDispatcher("/send121.jsp").forward(req, res);
	
      }



    }//doGet() over

}

OnetoOne.java

Code:
import java.util.*;

public class OnetoOne
{

   public List getMessages(String message)
    {	 
	List msg = new ArrayList();
	msg.add(message);
	return msg;
    }

    private final void _mththis()
    {
	messages = new LinkedList();
	messages_size = 25;
     }

     public OnetoOne()
     {
	_mththis();
     }

    private String name;
    private List messages;
    private int messages_size;

}
Now the problem i'm facing is that the message is getting stored in the ArrayListbut on the JSP side i'm not able to get it printed in the TextArea provided nor i'm able to get it on the server console for verifying purpose.

So if you could help me sort out the where the problem lies in my code I will be grateful to you.

Thanking you,
Jignesh