my dog learned polymorphism*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets through  Applets" Watch "Servlets through  Applets" New topic
Author

Servlets through Applets

manik kant
Greenhorn

Joined: Mar 24, 2008
Posts: 11
Hai..
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
Bye
manik
Todd Bush
Greenhorn

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.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
out.writeObject(objs);
out.flush();
out.close();

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
Sheriff

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.
Thanks.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets through Applets