ok first of all ... sample code
Sending info from applet to servlet :


  // make call to servlet server
    URL url = null;
    try {
      url = new
URL("http://www.my.com/servlets/ImageSoftware.ImageProcessing");  // point
towards the servlet u want to talk to
    }
    catch (MalformedURLException e) { System.out.println(e.getMessage()); }
    Properties props = new Properties();
// set arguments for servlet to receive in doGet
    props.put("Area", "2");
    props.put("ID", "59849");
    Object obj = null;
    try {
      InputStream in = sendGetMessage(props, url);
// open connection to servlet
      ObjectInputStream result = new ObjectInputStream(in);
// accept the serialized object returned from the servlet
      obj = result.readObject();
    }
    catch (IOException i) { System.out.println(i.getMessage()); }
    catch (ClassNotFoundException c) { System.out.println(c.getMessage()); }
    d = (Designer)obj;
// type cast to what object type should be

// this is the sendGetMessage Func used above
  public InputStream sendGetMessage(Properties args, URL u) throws
IOException {
    String argString = "";  // default
    URL servlet = u;

    if (args != null) {
      argString = "?" + toEncodedString(args);
    }
    URL url = new URL(servlet.toExternalForm() + argString);

    // Turn off caching
    URLConnection con = url.openConnection();
    con.setUseCaches(false);

    return con.getInputStream();
  }


Sending info from servlet to applet
Just use this function to send a serialized object to the servlets doPost
(Implement Serializable package in ure object)

  public void sendPostMessage(Serializable obj) throws IOException {
    URL url = null;
    try {
      url = new
URL("http://www.my.com/servlets/ImageSoftware.ImageProcessing");
    }
    catch (MalformedURLException e) { System.out.println(e.getMessage()); }
    URLConnection con = url.openConnection();

    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type",
                           "java-internal/" + obj.getClass().getName());
    ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
    out.writeObject(obj);
    out.flush();
    out.close();
    con.getInputStream();
  }

.... and the servlet accepts the object like this :

  public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
    ObjectInputStream in = new ObjectInputStream(request.getInputStream());

    // accept the image wrapper object
   ImageWrapper imWrap = null;
(ImageWrapper is just the name of my class)

    try { imWrap = ((ImageWrapper) (in.readObject())); }
    catch (ClassNotFoundException e) { Utils.trace(e.getMessage()); }
}


if u have any questions please .. do not hesitate to ask.

on ure second point  ... i need to know a few things .. like :
is it a stand alone app
is it run inside a browser
is it run outside a browser
what exactly do u want to do with it ??

Paul

-----Original Message-----
From: Julie liu <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Friday, September 24, 1999 5:58 PM
Subject: Re: Applet-Servlet Communication


>No, I didn't. If you can give me some code example, I appreciate.
>BTW, do you know how to keep the applet at the top all the time (I mean the
>applet is standlone and can't be hidden)?
>
>Julie.
>
>>have u tried passing serialized objects between the applet and servlet and
>>vice versa ?
>>If not .. i'm currently working on a project that does so ... i can give u
>>some code examples.
>>-----Original Message-----
>>From: Julie liu <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>Date: Friday, September 24, 1999 4:26 PM
>>Subject: Re: Applet-Servlet Communication
>>
>>
>> >Can S.B Help me?
>> >
>> >I would like to let the servelet and applet communicate with each other,
>> >actually I would like to use servelet to control the life time of
applet,
>>is
>> >that possible? and how can I keep the applet at the top all the time?
>> >
>> >Julie
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to