File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Signed applet talking to server other than its own Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Signed applet talking to server other than its own" Watch "Signed applet talking to server other than its own" New topic

Signed applet talking to server other than its own

Vishal Mungi

Joined: Mar 24, 2005
Posts: 24
The below Applet gives invalid stream header

//** The Signed Applet on the instance of Tomcat port 8080

public class EchoApplet extends Applet {
* Get a connection to the servlet.
private URLConnection getServletConnection()
throws MalformedURLException, IOException {

// URL urlServlet = new URL(getCodeBase(), "echo");
URL urlServlet = new URL("http", "localhost", 9090,
URLConnection con = urlServlet.openConnection();


return con;

* Send the inputField data to the servlet and show the result in the outputField.
private void onSendData() {
try {
// get input data for sending
String input = inputField.getText();

// send data to the servlet
URLConnection con = getServletConnection();
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);

// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();

// show result

} catch (Exception ex) {

//** The Servlet on the other instance of Tomcat port 9090

public class EchoServlet extends HttpServlet {
* Get a String-object from the applet and send it back.
public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
System.out.println("Inside Echo Servlet");
// read a String-object from applet
// instead of a String-object, you can transmit any object, which
// is known to the servlet and to the applet
InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
String echo = (String) inputFromApplet.readObject();

// echo it to the applet
OutputStream outstr = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstr);
} catch (Exception e) {


************ The same applet calling the servlet in its own container works.
Tiger Scott
Ranch Hand

Joined: Mar 01, 2001
Posts: 223
Applet can not talk to any other server than where it was downloaded from.
Vishal Mungi

Joined: Mar 24, 2005
Posts: 24
But i have seen examples of applets taking to other servers after being given the permission (net permission) to do so .. like the case of an applet polling various sites & assimilating info. In any case its not giving me a security exception which went off after i signed the applet.
I agree. Here's the link:
subject: Signed applet talking to server other than its own
It's not a secret anymore!