How can I detect the Java runtime installed on a c

2019-01-23 21:40发布

I have an ASP .NET website that hosts a Java applet. The Java applet requires version 1.6 Update 11 of the Java runtime.

How can I detect that a client has the appropriate runtime installed so that I can display an informative message if they do not?

Thanks,

Carl.

EDIT: The solution must be platform independant.

12条回答
欢心
2楼-- · 2019-01-23 22:18

If you don't mind using a basic java applet that requires a much older version to run, you could use this article and continue based on that result.

查看更多
何必那么认真
3楼-- · 2019-01-23 22:19

The link below was the way I got it to work. It has a JS you can get which was made for Java deployment. The link was mentioned above, but I thought an example with it would be nice.

These are samples that I ended up needing to fix my problem.

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit

Once you have downloaded the deployJava.js file you could put something to make sure java is installed: if (deployJava.getJREs().length > 0) { //Your code to start java }

Make sure a specific version is installed: if (deployJava.versionCheck(version)) { //Your version specific code }

Start the installer of the latest Java: deployJava.installLatestJava();

Or a specific version if you would like: deployJava.installJRE(version);

查看更多
Ridiculous、
4楼-- · 2019-01-23 22:22

The link below details on the deployment tips for java apps.

http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html

Quoting from the link

Deployment Toolkit To avoid browser compatibility issues, the Deployment Toolkit (deployJava.js) provides JavaScript functions that automatically generate HTML required to deploy applets and Java Web Start applications. Developers should invoke these functions to deploy their solutions in a consistent fashion across various browsers.

查看更多
祖国的老花朵
5楼-- · 2019-01-23 22:23
  1. Use deployJava.js function getJREs() to build a dynamic page depending on the user's Java version.

  2. Use http://cowwoc.blogspot.com/2008/12/tracking-java-versions-using-google.html to track the Java version being used by your web visitors using Google Analytics.

  3. Bonus step: use the source-code from step 2 as an example of how step 1 should be implemented.

查看更多
Explosion°爆炸
6楼-- · 2019-01-23 22:24

Just copy amd paste this code in your browser address bar! Check if it is useful for you.

javascript: for(i = 0; i < navigator.plugins.length; i++) alert(navigator.plugins[i].name);

You need to obtain the position of Java in the plugins array and maybe you can check the versions with a regular expression or something. You could take a look to the plugin javascript object.

Regards!

查看更多
放荡不羁爱自由
7楼-- · 2019-01-23 22:26

Maybe this script will help. This is Windows-only, though.

<script language='javascript' type='text/javascript'>
var javaVersion;
var shell;
try 
{
    // Create WSH(WindowsScriptHost) shell, available on Windows only
    shell = new ActiveXObject("WScript.Shell");

    if (shell != null) 
    {
        // Read JRE version from Window Registry
        try 
        {
            javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\");
        } 
        catch(e) 
        {
            // handle exceptions raised by 'shell.regRead(...)' here
            // so that the outer try-catch block would receive only
            // exceptions raised by 'shell = new ActiveXObject(...)'
            alert('error reading registry');
        }
    } 
} 
catch(e) 
{
    // Creating ActiveX controls thru script is disabled 
    // in InternetExplorer security options 

    // To enable it: 
    // a. Go to the 'Tools --> Internet Options' menu
    // b. Select the 'Security' tab
    // c. Select zone (Internet/Intranet)
    // d. Click the 'Custom Level..' button which will display the
    // 'Security Settings' window.
    // e. Enable the option 'Initialize and script ActiveX controls
    // not marked as safe'

    activeXDisabled = true;
} 

// Check whether we got required (1.6) Java Plugin
if ( javaVersion != null && javaVersion.indexOf("1.6")) 
{
    pluginDetected = true;
    alert('it is installed!')
}

if (pluginDetected) 
{
    // show applet page
} 
else if (confirm("Java Plugin 1.6 not found")) 
{
    // show install page
    alert('not found')
} 
else 
{
    // show error page
    alet('error')
}
</script>
查看更多
登录 后发表回答