My website features a Java Applet that needs to connect to the server. Interestingly, it successfully connects in JApplets @Override init(), but when called by JavaScript, it fails to do so.
final URL url = new URL(SERVER_URL + action);
System.out.println("url:" + url);
System.out.println("postString: " + postString);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if(!postString.isEmpty()) {
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", Integer.toString(postString.getBytes().length));
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
System.out.println("connecting...");
connection.connect(); // same with connection.getOutputStream();
System.out.println("connected");
....
The setup on my website:
<a href="javascript: document.applet.update();" title="update from server">Update</a>
<applet id="applet" archive="/public/Antucation-0.1.0.jar?random=3765332307555812156" code="de.antucation.controller.Controller.class" width="100%" height="800px">
<param name="colonyId" value="1">
</applet>
The output shows:
url:http://localhost:9000/applet/showCode
postString: colonyId=1
connecting...
I have tried putting a try-catch block around it with a System.out call, but no luck there either. However, calling
@Override public void init() { update(); }
works perfectly fine.
And yes, the applet is also hosted at http://localhost:9000/
How can I resolve this issue or find a workaround?