如果使用基本身份验证,Applet 将显示登录对话框 [英] Applet displays login dialog if basic authentication used

查看:25
本文介绍了如果使用基本身份验证,Applet 将显示登录对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网页上插入了一个 Java 小程序:

I have a Java applet inserted on a webpage:

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;

服务器正在使用基本身份验证.当 Chrome 或 Safari(或者更好的说法是 JVM)请求 MyApplet.jar 文件时,会显示需要身份验证"对话框,这很烦人.

The server is using Basic authentication. When Chrome or Safari (or better say JVM) requests the MyApplet.jar file the 'Authentication Required' dialog is displayed, that is very annoying.

我发现 Chrome/Safari(或 JVM)由于某种原因没有自动将身份验证:基本"标头附加到 GET 请求.

I have found that Chrome/Safari (or JVM) does not attach the 'Authentication: Basic' header to GET request automatically for some reason.

知道如何在请求 .jar 文件时强制附加 Authentication: Basic 标头以避免这个额外的登录对话框吗?

Any idea how to force the Authentication: Basic header to be attached when requesting .jar file to avoid this extra login dialog?

推荐答案

实际上,我认为问题可能在于您的小程序正在尝试打开与服务器的连接,服务器受到基本身份验证的保护.如果是这样,你需要在你的小程序中做这样的事情:

Actually, I think the problem might be that your applet is trying to open a connection back to the server, the server is protected by basic authentication. If so, you'd need to do something like this in your applet:

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

否则,只需将您的 .jar 文件移动到服务器上允许匿名读取访问的目录.

Otherwise, just move your .jar file to a directory on the server that allows anonymous read access.

这篇关于如果使用基本身份验证,Applet 将显示登录对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆