File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to get applet to talk to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to get applet to talk to servlet" Watch "how to get applet to talk to servlet" New topic
Author

how to get applet to talk to servlet

Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Given that an applet is restricted to the server it was loaded from, how to we have the server and applet do get and post to one another ... I would like to do binary data exchange, but realize Base64Encoder will likely be needed. I need to be able to transvers an arbitrary byte stream without any translation .... eg: 0xF0 (byte) 0x90 (byte) 0x8c (byte) 0xB5 ... which may include nulls or anything else. If need be, I will write a converter that maps 0x00 throught 0xff to char'a' through char'z' and unpack it on each end as needed. I already have the applet and the servlet code underway and in the build directory along with the rest of my project.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
You should examine the appropriate library classes, namely java.net.HttpURLConnection and related classes.

These will enable you to create GET or POST requests to a servlet and transmit text or binary data. No need to get fancy with a converter, just pay attention to the Content-type and Content-length headers.

Bill


Java Resources at www.wbrogden.com
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Okay, so it's: I am on the network already, just use it with the java.net tools and any constraining of the applet talking to only the server it came from can be thought of in OO terms as having been done by the engineers already when I got here.

Thank you, I will proceed to write on that basis.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you search the web for 'HTTP Tunneling', 'applet', and 'servlet' you should be able to find plenty of examples.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Okay, I worked on it yesterday using primarily the sources in java.net and sample servlet code. I decided to approach this with the idea that using the advice already given, the applet code can 'phone home' using name-value pairs and POST/PUT. What I need to focus on today is how Tomcat maps URI's to servlets and jsp's. For the moment, I saw HttpURLConnection is abstract, so I am sorta stuck at the moment wondering if I should use the design pattern of a utility class in the same file extending HttpURLConnection to get the benifit of having the work for PUT correctly done and already avialable. I did read that http/put can handle binary nulls and fixed block size without going through base64 encoder - that is an immediate design goal of posting the question so progress already.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get applet to talk to servlet
 
Similar Threads
*urgent : mirror-ing string content to byte...
Zip Streams
Basic concept in Applet-Servlet communication ?
Can applet be part of webpplication ?
no suggestions found