CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2001
    Posts
    5

    Applet needs to warn a servlet

    I need my applet warns a servlet that it is finilizing, from stop() method (for instance). I am doing an url call, into my applet stop method, like:

    try
    {
    URL StopConnection = new URL(getCodeBase()+"/myServlet");
    try
    {
    URLConnection sc = StopConnection.openConnection();
    } catch (IOException e)
    {
    System.out.println("Exception ending applet " + e);
    return;
    }
    } catch (Exception e) {
    e.printStackTrace();
    }

    It does not work, maybe there is something wrong or it is impossible to do what i need to. If someone has an idea, please, i will apreciate it!

    Maribel


  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Applet needs to warn a servlet

    How does it fail? Does the connection fail? does it throw an exception? How does the servlet know it is a finalize warning? Does the servlet get the message?

    If it's a problem with the connection, here's a reliable way of making one:URL currentPage = getCodeBase();
    String protocol= currentPage.getProtocol();
    String host = currentPage.getHost();
    int port = currentPage.getPort();
    String urlSuffix = "/servlet/MyServlet";
    URL dataURL = new URL(protocol, host, port, urlSuffix);
    URLConnection connection = dataUrl.openConnection();
    ...

    Dave

    To email me remove '_spamjam' from my email address
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Applet needs to warn a servlet

    I tried some experiments with an applet's stop() method using code that worked in the init() method. I used both IE5.5 and Netscape 4.? No messages were sent to my localhost server from the stop() method. So is my code bad or does the browser NOT allow communication from the stop() method?

    Norm
    Norm

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Applet needs to warn a servlet

    I changed my code and was able to send a message to the server from the applet's stop() method using a Socket. Forget the other message

    Norm
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured