Problems with developing a chatroom

Hi all,
I am new to jsp and am learning. I need some help. I am developing a chat room application. I am using AJAX to update the screen. Since JSP caches the data, I am using a servlet code for AJAX alone. For others I use JSP as the server coding.
Suppose consider i am logging in as 'user1', I am able to receive other users message only if I trigger any event.
Can you please help me to get others message automatically? Here is my code:
//This jsp code validates the user and provides the chat room screen...
<%--Login validation--%>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html" %>
<html>
<head>
<title>Login Result</title>
<script src="http://localhost:8080/ChatRoom/ChatScript.js" type="text/javascript"></script>
</head>
<body>
<%
String uid=request.getParameter("id");
String pwd=request.getParameter("pwd");
String tmp_uid="";
String tmp_pwd="";
String welcomeName="";
String onlineMembers="";
String buddyList="";
     Connection con;
     PreparedStatement ps;
     ResultSet rs;
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con=DriverManager.getConnection("jdbc:odbc:LoginDB");
     String str="select * from login where uname=?";
     ps=con.prepareStatement(str);
     ps.setString(1,uid);
     rs=ps.executeQuery();
     while(rs.next())
          tmp_uid = rs.getString("uname");
          tmp_pwd = rs.getString("pwd");
          welcomeName = rs.getString("fname");          
     if(uid.equals(tmp_uid)&&pwd.equals(tmp_pwd))
          Cookie ck = new Cookie("user",uid);
          response.addCookie(ck);
          try{
          String setStatus="update login set status='1' where uname=?";
          ps=con.prepareStatement(setStatus);
          ps.setString(1,uid);
          ps.executeQuery();
          }catch(Exception e){}
%>
          <form method="post" action="logout.jsp">
<%
          out.print("Welcome "+welcomeName+" ! ");
          //out.print("<input type=\"hidden\" name=\"username\" value="+uid+">");
%>
          <input type="submit" value="Logout"></form><hr>
<%          
          String checkStatus="select uname from login where status=?";
          ps=con.prepareStatement(checkStatus);
          ps.setString(1,"1");
          rs=ps.executeQuery();
          while(rs.next())
               tmp_uid = rs.getString("uname");
               onlineMembers=onlineMembers.concat(tmp_uid+"\n");
          String friends ="select * from vijay";
          ps=con.prepareStatement(friends);
          rs=ps.executeQuery();
          while(rs.next())
               String buddy = rs.getString("buddy");
               buddyList = buddyList.concat(buddy+"\n");
%>
          <form action="#" name="chatForm">
          Buddy List
          <pre><textarea cols=19 rows=20 readonly="readonly" name="BuddyList">
<%
          out.println(buddyList);
%>
          </textarea> <textarea cols=72 rows=20 readonly="readonly" name="ReceiveText"></textarea> <textarea cols=19 rows=20 readonly="readonly" name="OnlineList">
<%
          out.println(onlineMembers);
%>
          </textarea></pre>
          Type your text here!
          <pre><b><textarea cols=90 rows=3 name="SendText"></textarea></b> <input type="button" value=" Send " onclick="sendRequest(SendText.value,user.value)"/></pre>
<%
          out.print("<input type=\"hidden\" name=\"user\" value="+uid+">");
%>
          </form>
<%
     else
%>
          <jsp:include page="INVALID_USER_HOME.HTML" flush="true"/>
<%
     con.close();
%>
</body>
</html>
//This is script for AJAX
var request;
var address;
function getRequestObject()
if (window.ActiveXObject)
return(new ActiveXObject("Microsoft.XMLHTTP"));
else if (window.XMLHttpRequest)
return(new XMLHttpRequest());
else
return(null);
function sendRequest(str,username)
address = "http://localhost:8080/ChatServlet/AjaxServer";
address = address+"?text="+str;
address = address+"&name="+username;
request = getRequestObject();
request.onreadystatechange = handleResponse;
if((str.length>0)&&(username.length>0))
request.open("GET",address,true);
request.send(null);
setTimeout("sendRequest()",500);
function handleResponse()
if ((request.readyState == 4)&&(request.status == 200))
     document.chatForm.ReceiveText.value = request.responseText;
     document.chatForm.SendText.value = "";
//This is the servlet for servicing the AJAX requests:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ChatServlet extends HttpServlet
     PrintWriter out;
     static String message = "";
     String sendText = "";
     String name = "";
     public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
          response.setHeader("Cache-Control", "no-cache");
          response.setHeader("Pragma", "no-cache");
          response.setContentType("text/html");
          sendText = request.getParameter("text");
          name = request.getParameter("name");
          PrintWriter out = response.getWriter();
          java.util.Date d = new java.util.Date();
          String date = String.format("(%tr)",d);
          message = message.concat(date+name+" : "+sendText+"\n");
          out.println(message);
}

Using a javascript timer is one method to go with.
Another would be the 'Pushlet'. A pushlet is a servlet that never closes the output stream to the client. You would probably make an IFrame or something to that affect that opens up a pushlet servlet. When an incoming message is recieved, your servlet that takes the input forwards to the message to the pushlet which sends the data to the second user -probably using a javascript command.
To make it work you have to hold a map of all the open connections. Your chat request from AJAX would have to identify which open connection(s) get the message.
Look up Pushlets via google.

Similar Messages

  • Problem with develop module

    I have LR 5.4 running on a mac OS 10.7.5. I am having problems with the software locking up in the Develop module. Sometimes a new image won't open and the preview screen stays black. I go back to the Library module and try to reneter the Develop module and get an error message saying there was an error trying to open the module. The entire LR screen is gray. I have to quit LR and restart the software to continue. I downloaded my software from Abobe and I was wondering if I can download a new version again and use my same serial number to reinstall the software.

    Hi Rodney,
    No custom print templates and this is a relatively new problem. It just
    started about a week ago. I have been using the software steady for months
    now. It did it once or twice last week but this weekend and today it has done
    it about six times so it seems the problem is getting worse. That¹s why I
    think the software may have been corrupted. I didn¹t keep a copy of the
    software I downloaded so I can¹t reinstall. That¹s why I was wondering if I
    could download it again and use the same serial number as before. I have only
    loaded the latest version on my desktop. I also have LR 4 still installed on
    my laptop and desktop. I have a big project to complete and this is really
    slowing me down.
    Michael
    Problem with develop module
    created by Andrew Rodney <https://forums.adobe.com/people/thedigitaldog>  in
    Photoshop Lightroom - View the full discussion
    <https://forums.adobe.com/message/6445126#6445126>
    Do you have any custom print templates? That might be the case, it was an
    issue at one time. Delete them and try using one of the default presets.
    Crash?
    Please note that the Adobe Forums do not accept email attachments. If you want
    to embed a screen image in your message please visit the thread in the forum
    to embed the image at https://forums.adobe.com/message/6445126#6445126 Replies
    to this message go to everyone subscribed to this thread, not directly to the
    person who posted the message. To post a reply, either reply to this email or
    visit the message page:  To
    unsubscribe from this thread, please visit the message page at
    . In the Actions box on the
    right, click the Stop Email Notifications link. Start a new discussion in
    Photoshop Lightroom by email
    <mailto:[email protected]>  or
    at Adobe Community
    <https://forums.adobe.com/choose-container.jspa?contentType=1&containerType=14
    &container=3316>  For more information about maintaining your forum email
    notifications please go to http://forums.adobe.com/thread/416458?tstart=0.
    >

  • Windows 98 resource & memory problems with Developer/2k v2.1

    Hi All
    I have just started developing with Developer/2000 v2.1 on
    Oracle v7.3. I recently purchased a Dell Inspiron 3500 notebook
    PC running Windows 98 (64M RAM, 4.3G HD). I have had continuous
    problems with the system running out of system resources and/or
    memory.
    The problem seems to be with both the development and runtime
    programs. If I run the Form Builder and then exit it, the system
    information program reports that the F50DES32.EXE is still
    running, plus there are a load of 32-bit driver files left in
    memory. The same problem occurs with the runtime, in that once
    it's loaded, even after taking the exit option, the F50RUN32.EXE
    is left running in memory. This would not be so bad if
    subsequent loads of either program recognised that the program
    was already running, but they do not so you end up with multiple
    copies of the programs running. At the moment, with regular
    changes, recompiles and reloads of the runtime going on, I have
    to reboot the PC on average about once every 30 minutes.
    I cannot find anything on either the Microsoft or Oracle web
    sites about this problem, and really I'm not sure who's to
    blame. I guess development on Windows 98 is still pretty young.
    However, this seems to be a fairly serious problem and is
    certainly having a major impact on productivity!
    Am I missing something in terms of Oracle parameter settings or
    in the way Windows 98 is set up? Has anybody out there had
    similar problems? Can anybody help??
    Thanks
    Billy
    null

    I also observed something like this- but it was a programming error. I was using ADODB in LabVIEW to run SELECT statements and retrieve data from recordsets. My program would gradually consume more and more RAM over time. This was plainly visible on NTs Task Manager. My problem was that I was simply forgetting to close/destroy many of the object references. This would also sometimes cause my system to crash when I stopped the program and exited LabVIEW (or exited the run-time engine if it was an exe).
    I might suggest you go through the program and make sure you use the Automation Close function to close the appropriate references.
    Its especially important to close all "Fields" and "Field" references.
    Also, I found that running the GET ROWS method or GE
    T STRING method on a recordset works much better than retrieving data using "Fields" and "Field" objects... its faster, easier, less prone to causing problems, less trouble with references and stuff.

  • MiniSAP - Problems with developer key

    Hi @all,
    today, I started installing the Minisap System on my PC. (SAP NetWeaver Sneak Preview on MaxDB).
    After the installation I logged on to the System with the User "BCUSER".
    I started t-code "SE38" to start developing some ABAP programms.
    Now, I have to insert a valid developer key, which I can - according to the Installation Guide - find on<a href="http://www.sap.com/technology/minisap">http://www.sap.com/technology/minisap</a>.
    The key I found there is: 29671482393151224771
    So I entered this key in the field, but my System said, it was an invalid key.
    Can anyone help me with this problem?
    I checked many potential nonconformities, but had no success:
    - I definitly inserted the correct key found on the website, because I used the copy and paste function.
    - I restarted both the instance and after that the whole pc.
    - I installed a new valid 90-day license key from SAP
    - My SID is definitly "NSP", Installation-Number: "DEMOSYSTEM"
    Does anyone has an Idea, how I can resolve this problem? Is there another developer key available for the NSP WebAS 6.40 System?
    Thank you for answering
    Best regards
    Ralf

    Thank you,
    I tried to solve my problem on the way you said, but again, the error message "invalid key" appeared.
    Is it possible, that there is a general problem with my installation?
    Is there anyone else with the same problem?
    Regards
    Ralf

  • Problem with developer

    Hi all
    Im having a problem with my instalation od SQL developer, i initialy installed and set it up and was able to create and run packages.
    the dba then changed ny permissions to allow greater access to more data and mow i get an error when trying to access packages and procedures the error is as follows
    table or view does not exist --- vendor code 942 please can you help

    Ok, that's slightly different, that's about what you can see, depending on privileges. We have a few bugs on that and have now earmarked these for the next release.
    The issue as I understood from the initial query, was that having had the privilege level changed you erroneously got this table or view does not exist for any procedures or packages.
    Either way, bugs are logged and noted.
    Sue

  • Video Playback Problem with Developer Walkthrough of the Continuous Measurement and Logging Sample Project

    Hi!
    I have serious problems playing the video Developer Walkthrough of the Continuous Measurement and Logging Sample Project.
    As the video pauses every few seconds for buffering. I am not able to watch it. Just wanted to check if you can playback the video:
    http://zone.ni.com/wv/app/doc/p/id/wv-3401
    This happens on any browser (chrome, ie, firefox). I am using Win XP and the latest Adobe Flash Player. About 2 weeks ago NI Germany confirmed the problem and promised to contact NI USA as they are responsible for these videos. So far nothing happened. In the meantime I received an e-mail that the problem could not be confirmed although they had confirmed it before...
    Thank you for any feedback.
    Regards,
    Anguel

    Hello ctVolFan,
    As indicated in the "support" section of the SPOT, you should get in touch with self-paced-training(at)ni(dot)com.  I don't believe that team monitors these forums directly.
    Regards,
    Tom L.

  • Picture problem with developer 6i

    Hi all
    I am using BLOB data type for storing a picture in oralce 9i database server. I have image type item on my forms (Developer 6i). I am using following code to add picture to my image item.
    READ_IMAGE_FILE('mypicture.bmp','bmp','CAMPUS_PICTURE.PHOTO_PIC');
    Data is successfully saved in database. But when I retrieve the data, picture is not displayed. Similarly image gives error on reports.
    Same data type is working perfectly with oracle 8i and developer 6i.
    Can any one tell me the reason and how to save picture in database using BLOB?
    Regards
    Vijay.

    Hi,
    You need to use SQL*Net to communicate between the 8.0.6 home (used for Developer) and the 8.1.7 home used by the database. Make sure the TNS listener is started for the database and use the SQL*Net alias (don't leave the Database field blank) when connecting using Developer.
    Regards.
    Robert.
    I have successfully installed Oracle 8i enterprize edition 8.1.7.0.0 on Windows 2000 professional and it is working fine.
    But
    When I have installed Developer 6i, The Developer 6i is not communicating with the 8i database. What wrong am i doing.
    I have installed developer 6i on different oracle home as advised by my friend, and some other stuff also as exporting the registry key of oracle in hkey local machine and after installing developer 6i importing the exported registry key, But By all doing this I am still not able to connect to oracle 8i database,
    What i'm doing wrong.
    If any one knows the problem Please send a reply.
    Thanks in advance

  • Odd problem with developer key

    Hi experts,
    I was trying to create a Program in Abap editor and the system asked me for a developer key when I gave a random Program name. I changed the program name and I got the attributes screen. Can someone explain why I got this problem.
    Ex. 0201 - Problem
           Ztryone - No problem

    I think you have to use proper naming convention while creating ABAP objects. All custom build ABAP objects should srart with Y or Z. All other are reserved for SAP delivered objects.

  • Problems with developing a VSS hardware provider

    Hi all,
    When I develop VSS hardware provider, I had a question..
    Why "VSS Requester"(such as vshadow.exe) create a snapshot(DoSnapshotSet), "VSS Backup Components" flow chart always do
    LocateLuns and FillInLunInfo:
    AreLunSupported -> BeginPrepareSnapshot -> ... -> CommitSnapshots -> ... -> GetTargetLuns ->
    LocateLuns -> FillInLunInfo -> PreFinalCommitSnapshots -> PostFinalCommitSnapshots -> Finish.
    How can I create a snapshot without "Auto Import".
    I don't want to do auto import when I create a snapshot...
    Thanks all..
    Wei-Cheng.

    WeiChengLai,
    I'm trying to skip auto-import block but I'm having problems. If requester set snapshot context:
    VSS_CTX_FILE_SHARE_BACKUP | VSS_VOLSNAP_ATTR_TRANSPORTABLE at requester side.
    than it skips auto-import block and everithing goes fine.
    However, if there are Writers involvment in snapshot than I can not use this context, only:
    VSS_CTX_APP_ROLLBACK | VSS_VOLSNAP_ATTR_TRANSPORTABLE
    than it alwasy goes trough auto import block (LocateLuns() FillLunInfo()).
    What is yourexpirience?
    Best regards,
    Ljubo

  • Having problem with develop module

    When I take a pic from library to develop module, I get the "loading" message but then it doesn't go off (and doesn't load); this is a new problem; hasn't happened before; I don't know if recent loading of 2.6 version caused a problem. Thanks for any insight.

    Is there anyone that can help? This is frustrating to say the least. The edits are taking effect, but only showing on the filmstrip. If I go back to library the edits are there, and will then show in develop when I take it back again. This makes it just about impossible to apply anything like cloning, or minute edits, because I can't see them when they happen!!

  • Problem with developer key

    Hi,
    I am a MiniSAP user. I wanted to write ABAP's programs but I cant change repository objects. I followed the instructions on www.sap.com/minisap with expanding my license and it worked. However as I enter developer key from that site (it is already provided) I still cant change these objects. Why is that? Can't I work as developer in MiniSAP? Please help me. Thank you in advance.

    Right, you can not change objects outside of the name space.  Create your program with the name Z_FIRST_PROGRAM.  There is no reason why you must use S_FIRST_PROGRAM for your program name.  Do not delete the S_FIRST_PROGRAM, just create your "Z" program.
    NSP is the system id for the Sneak Preview Netweaver 2004s, I assumed that you where working with this system.
    Anyway, the rule is still the same,  you must respect the namespace rules. 
    Welcome to SDN!  Please remember to award points for helpful answers and mark your thread as solved when solved completely.  Thanks.
    Regards,
    Rich Heilman

  • Install problems with developed app

    i have developed an app on NT. i used the delivery wizard of project builder to generate installer scripts to install it. It installed fine on NT (nt.prd).
    But when i install in on win 95(win95.prd), it installs and then when its trying to register the product, it crashes. the app runs fine, but it does not register on the machine as an oracle product. and so i cannot uninstall it.
    So, i tried compiling the forms and creating the installation package using project builder on 95. also tried the file packager.
    it gives me the same problem. crashes the installer at the end of installation
    is this a bug ?
    Thanks for taking the trouble to read thru this. Any help would be appreciated.
    Pat.
    null

    I have a same Problem, Do you can tell me the solution ??
    Thanks !!
    Do You speak spanish ??

  • JDAPI problem with Developer 10g10.1.2.3

    Hi,
    I am trying to make some automatic changes to some forms using JDAPI. The process run smooth when using instalations of Developer 9.0.4 and Developer 10g10.1.2.0.2. When using Developer 10g10.1.2.3 I get a "Can´t open file" and "Unable to create new form context" error. My customer only has Develper 10g10.1.2.3.
    Any suggestions?
    Thanks in advance.

    Helllo,
    Yes, I think I did. I have tried, with that version, in Windows 2000, in Linux and in Unix with the same result in all the cases.

  • Upgrade To 4.2 Problem With Developer Toolbar

    We have just upgraded our first environment to 4.2.
    Have just checked the applications and the developer toolbar is appearing as a vertical list at the bottom left hand side of the page.
    This is true for all applications in this workspace and they all use theme LightBlue 15.
    Help appreciated
    Gus

    Hope this is what you asked for.
    From web inspector
    i/themes/theme_15/theme_3_1.css
    From Template Page Header
    <html lang="&BROWSER_LANGUAGE." xmlns:htmldb="http://htmldb.oracle.com">
    <head>
    <title>#TITLE#</title>
    <link rel="stylesheet" href="#IMAGE_PREFIX#themes/theme_15/theme_3_1.css" type="text/css" />
    #APEX_CSS#
    #TEMPLATE_CSS#
    #THEME_CSS#
    #PAGE_CSS#
    #APEX_JAVASCRIPT#
    #TEMPLATE_JAVASCRIPT#
    #APPLICATION_JAVASCRIPT#
    #PAGE_JAVASCRIPT#
    #HEAD#
    </head>
    <body #ONLOAD#>#FORM_OPEN#Page Source Head Element
    <html lang="en-us" xmlns:htmldb="http://htmldb.oracle.com">
    <head>
    <title>Countries</title>
    <link rel="stylesheet" href="/i/themes/theme_15/theme_3_1.css" type="text/css" />
    <link rel="stylesheet" href="/i/css/apex.min.css?v=4.2.0.00.27" type="text/css" />
    <!--[if IE]><link rel="stylesheet" href="/i/css/apex_ie.min.css?v=4.2.0.00.27" type="text/css" /><![endif]-->
    <link rel="stylesheet" href="/i/libraries/jquery-ui/1.8.22/themes/base/jquery-ui.min.css" type="text/css" />
    <script type="text/javascript">
    var apex_img_dir = "/i/", htmldb_Img_Dir = apex_img_dir;
    </script>
    <script src="/i/libraries/apex/minified/desktop_all.min.js?v=4.2.0.00.27" type="text/javascript"></script>
    <script src="/i/libraries/apex/minified/legacy.min.js?v=4.2.0.00.27" type="text/javascript"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>Gus

  • Problem with Mail, and Placceholder Columns in Report 2.5

    I have two problem with Developer/2000 Report 2.5:
    1. What should I configure in order my Report 2.5 can
    mail the report output to Microsoft Mail or MS Exchange ?
    2. Placeholder Columns have an Edit PL/SQL code as Formula
    columns. But when I fill the trigger at Placeholder columns
    there always some error. I never know the functions of
    trigger at placeholder columns. is it a bug at Report 2.5 ?,
    if not please tell me how can I use the placeholder
    columns trigger ?
    Thank you.
    Herry H.S.
    null

    I found out the problem... not a problem at all... thank you...

Maybe you are looking for