Java ';无法识别浏览器类型';使用Internet explorer 11时显示的消息
我已经编写了一个java代码来更新软件并查看更新状态。 我已经在eclipse中编写了代码,我希望使用GUI更新软件。 在GUI中,有一个链接单击,我们可以看到更新状态。Internet Explorer 11是默认浏览器。但单击该链接时,会显示一条名为的错误消息 显示“无法识别浏览器类型”消息 这是我的java代码:Java ';无法识别浏览器类型';使用Internet explorer 11时显示的消息,java,internet-explorer,Java,Internet Explorer,我已经编写了一个java代码来更新软件并查看更新状态。 我已经在eclipse中编写了代码,我希望使用GUI更新软件。 在GUI中,有一个链接单击,我们可以看到更新状态。Internet Explorer 11是默认浏览器。但单击该链接时,会显示一条名为的错误消息 显示“无法识别浏览器类型”消息 这是我的java代码: protected static void retrieveIAInfo() { String appString = readDefaultBrowserCo
protected static void retrieveIAInfo() {
String appString = readDefaultBrowserCommand();
// XTSce63590: manage Mozilla and Firefox
// commandline in the registry
if (isIE(appString)) {
m_DefaultBrowserPath = extractIECmd(appString);
} else if (isMozilla(appString)) {
m_DefaultBrowserPath = extractMozillaCmd(appString);
} else if (isFireFox(appString)) {
m_DefaultBrowserPath = extractMozillaCmd(appString);
} else {
throw new RegistryUtilitiesException("Unable to identify browser
type.",RegistryUtilitiesException.NO_BROWSER);
}
if (m_DefaultBrowserPath== null) {
throw new RegistryUtilitiesException("Unable to identify brwoser
type.",RegistryUtilitiesException.NO_BROWSER);
}
System.out.println("IABrowserPath: " + m_DefaultBrowserPath);
}
protected static String extractIECmd(String cmd) {
String browser_cmd = null;
//int index = cmd.toLowerCase().lastIndexOf ("-nohome");
int index = cmd.toLowerCase().lastIndexOf ("-url");
if (index != -1) {
cmd = cmd.substring(0, index);
// if (cmd.charAt(0) == '"') {
// index = cmd.toLowerCase().lastIndexOf ("\"");
if (cmd.charAt(0) == '"') {
index = cmd.toLowerCase().lastIndexOf ("%1");
if (index != -1) {
browser_cmd = cmd.substring(1, index);
}
}
}
return browser_cmd;
}
在函数RetrieveAINFO中,当调用extractIECmd(appString)时,函数始终返回false。因此,抛出命令
“无法识别浏览器类型”
在RetrieveInfo中正在执行。
对于其他浏览器,如Mozilla,没有问题。只有在iInternetExplorer11浏览器的情况下,才会引发异常
cmd正在从以下寄存器值提取索引:
C:\Program Files\Internet Explorer\iexplore.exe“%1”
有人能帮我在函数extractIECmd中将%1的值作为变量的lastIndexOf吗?我已经提到,Internet explorer 11以外的浏览器都工作正常。 为了解决这个问题,我们必须提取InternetExplorer11的寄存器值 “C:\Program Files\Internet Explorer\iexplore.exe\%1” 删除%1并获取C:\Program Files\Internet Explorer\iexplore.exe 这可以通过将“extractIECmd()”函数更改为 受保护的静态字符串提取器ecmd(字符串qq){ } 现在Internet Explorer也可以正常工作了 问题解决了
String browser_cmd = "";
*int index = qq.toString().lastIndexOf ("");*
if (index != -1) {
qq = qq.substring(0, index);
if (qq.charAt(0) == '"') {
index = qq.toLowerCase().lastIndexOf ("\"");
if (index != -1) {
browser_cmd = qq.substring(1, index);
}
}
}
return browser_cmd;