File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Calling a Servlet from an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling a Servlet from an Applet" Watch "Calling a Servlet from an Applet" New topic

Calling a Servlet from an Applet

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
How can I pass things (parameters,strings,...) from an applet to a Servlet?.
I'm connected from the Applet to the Servlet with its URL.I get URL's OutputStream and send a string.
In the Servlet I'm trying to read the sended string with the ReadLine() method but the servlet don't run good. It waits for something to read that never arrives.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Here is an example of an applet calling a servlet by passing it an object and then getting an object back from the servlet. The rule is the objects passed back and forth must be serializable. So you could pass a String containing a SQL statement from the applet to the servlet and get back a Vector (not a ResultSet which isn't serializable) from the servlet.
This example is very simple. All the applet does is pass an object to the servlet which adds 10 to an int inside the object and then passes the object back again.
Here is the class passed back and forth:

Here is the applet.

Here is the servlet:

[This message has been edited by Thomas Paul (edited February 28, 2001).]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: Calling a Servlet from an Applet
It's not a secret anymore!