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

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

问题描述

我有一个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.

我发现铬/ 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文件,以避免额外的登录对话框时附加

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.

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

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