Applet URLConnection.connect fails after being called from JavaScript

I have a website with a Java Applet and that applet needs to connect to my server. This works in JApplets @Override init() but not in my own functions that are being called by javascript.

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.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Content-Length", Integer.toString(postString.getBytes().length));

    connection.connect(); // same with connection.getOutputStream();


<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">


postString: colonyId=1

I have a try catch around it with a System.out call but nothing happens there either. However this works absolutly fine:

public void init() {

Oh and the applet of course also comes from http://localhost:9000/

How do I work around this or fix it?


Try something along the lines of:

public void callFromJavaScript(final String param) {
    AccessController.doPrivileged( new PrivilegedAction<Void>() {
        public Void run() {
            // call code to make the connection..
            return null;

Need Your Help

Search for null field in Linq query

c# .net sql-server linq tsql

Using T-SQL in SQL Server Management Studio this query returns exactly what I am expecting

AJAX requests: How can I implement an “else” condition for unhandled HTTP status codes?

jquery ajax switch-statement http-status-codes

I am trying to react to the HTTP status codes in some AJAX. I am successful in reacting to specified status codes, but I do not want to have to check for every single one. Is there a way to write an

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.