File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlets through  Applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets through  Applets" Watch "Servlets through  Applets" New topic

Servlets through Applets

manik kant

Joined: Mar 24, 2008
Posts: 11
I want to pass the values from
an Applet to a servlet and from there
i want to print ..i am new to servlets
so please give me an idea...
Advance Thanzzz
Todd Bush

Joined: Mar 06, 2000
Posts: 14
Passing data between applets and servlet is quite easy. I've implemented a solution passing data as serialized objects using ObjectOutputStream and ObjectInputStream.
In the applet...
URL url = new URL("servlet/myServlet");
Integer data = new Integer(1);
Serializable objs = data;
URLConnection con = url.openConnection();
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

In the servlet....
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
Integer myData = (Integer)in.readObject();
And of course you can send data the other way.
Hope this helps.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Please note that The Java Ranch has a naming policy, described here and "manik" is not a valid name. Please choose one which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Servlets through Applets
It's not a secret anymore!