JSP - Applet communication


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JSP - Applet communication

  1. #1
    Jo Desmet Guest

    JSP - Applet communication

    Using servlets it is possible to setup a Servlet-Applet (or a Servlet-client
    application in general) communication through http-post messages. Is there
    anyway to do simular things with JSP, or is a Servlet still the preferred
    way of setting up HTTP-post mechanisms?


    Share on Google+

  2. #2
    Larne Pekowsky Guest

    Re: JSP - Applet communication

    In article <399878bd$1@news.devx.com>, Jo Desmet <jo_desmet@yahoo.com> wrote:
    >Using servlets it is possible to setup a Servlet-Applet (or a Servlet-client
    >application in general) communication through http-post messages. Is there
    >anyway to do simular things with JSP, or is a Servlet still the preferred
    >way of setting up HTTP-post mechanisms?


    Hi Jo,

    The good news is that since JSPs are automatically converted into
    servlets, anything you can do in one you can do in the other. In fact
    there are several ways you can handle this sort of communication in a
    JSP.

    If your applet is sending form-like data (that is, name/value pairs
    separated by ampersands) then you can just use beans to receive these
    values directly. So, if your applet sends something like
    "animal=fish&color=gold", and you have a bean named handler that has
    setAnimal() and setColor() methods, then you can just include this in
    your JSP:

    <jsp:setProperty name="handler" property="*">

    and everything will just work. Beans are cool...

    Alternately, if your applet is sending some arbitrary data you can
    handle it much as in a servlet. In a servlet you might do something
    like:

    InputStream in = request.getInputStream();
    StringBuffer buffy = new StringBuffer();
    byte data[] = new byte[1024];
    int count;

    while((count = in.read(data)) > 0)
    buffy.append(new String(data,0,count));

    in.close();

    String postdata = buffy.toString();

    You can do the same thing in a JSP by enclosing all of the above in a
    <java></java> block. You could then send postdata to a bean with a
    setPostdata() method. Or, you could move all of the above code into a
    bean, and send the whole request to the bean with something like:

    <jsp:setValue name="bean" property="request"
    value="<%= request %>">

    This is probably the cleanest option, at least for those building
    pages. In either case, once the bean has the data, it can do whatever
    it needs to with it, and then make other properties available to the
    rest of the page.

    Hope this helped!

    - Larne
    Share on Google+

Similar Threads

  1. Voice Communication using Java applet
    By Rey Morejon in forum Java
    Replies: 13
    Last Post: 03-30-2008, 02:03 AM
  2. Applet - Api Server Communication
    By Gautham Kasinath in forum Java
    Replies: 1
    Last Post: 04-14-2006, 03:52 PM
  3. Replies: 3
    Last Post: 08-23-2001, 11:01 AM
  4. Replies: 1
    Last Post: 08-10-2000, 12:35 PM
  5. Replies: 1
    Last Post: 08-10-2000, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center