Java – if basic authentication is used, the applet displays the login dialog box

I inserted a java applet on the web page:

applet = '<embed'
    + ' type="application/x-java-applet;version=1.6"'
    + ' pluginspage = "http://www.java.com/en/download/"'
    + ' width="0" height="0"'
    + ' style="position: absolute"'
    + ' archive="/plugins/MyApplet.jar"'
    + ' code="MyTestApplet.class"'
    + '>'

appletContainer.innerHTML = applet;

The server is using basic authentication When chrome or Safari (or better, JVM) requests myapplet Jar file, the "need validation" dialog box is displayed, which is very annoying

I found that chrome / Safari (or JVM) did not automatically attach the "authentication: basic" header to the get request for some reason

Any idea of how to force in the request Jar file with authentication: basic header to avoid this additional login dialog?

Solution

In fact, I think the problem may be that your applet is trying to open and connect back to the server, which is protected by basic authentication If so, you need to do the following in the applet:

// http://www.coderanch.com/how-to/java/AppletsFaq#authentication
  String authorization = Base64Coder.encode(username + ":" + password);
  connection.setRequestProperty("Authorization","Basic " + authorization);

Otherwise, simply remove the The jar file is moved to a directory on the server that allows anonymous read access

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>