Applet和JSP通信

发布于 2024-10-15 05:47:01 字数 866 浏览 1 评论 0原文

我想获取在客户端加载小程序后动态分配的变量的值。 Applet 嵌入在 JSP 页面中。我想在该 JSP 页面中获取该值。源代码如下:

public class CheckJavaVersion extends Applet 
{ 
private static Label versionCheck; 
public static String javaVersion; 
public void init() 
{ 
try 
{ 
Color colFrameBackground = new Color(198, 0, 0); 
this.setBackground(colFrameBackground); 
versionCheck = new Label("Java Version:"+System.getProperty("java.version")); 
this.add(versionCheck); 
javaVersion = versionCheck.getText(); 
} 
} 

JSP 页面:

<html> 
<head><title>Display Java Version</title> 
</head> 
<body> 
<jsp:plugin code="com.applets.CheckJavaVersion" codebase="/AppletURLComm" type="applet"> 
</jsp:plugin> 
</body> 
</html> 

现在我想访问JSP 页面中的javaversion 变量。如果我访问该变量,它会给出 null 值。如何获取变量的值?

I want to get the value of a variable which is dynamically assigned after the applet load in client side. Applet is embedded in a JSP page. Within that JSP page I want to get that value. Source code is given below:

public class CheckJavaVersion extends Applet 
{ 
private static Label versionCheck; 
public static String javaVersion; 
public void init() 
{ 
try 
{ 
Color colFrameBackground = new Color(198, 0, 0); 
this.setBackground(colFrameBackground); 
versionCheck = new Label("Java Version:"+System.getProperty("java.version")); 
this.add(versionCheck); 
javaVersion = versionCheck.getText(); 
} 
} 

JSP Page:

<html> 
<head><title>Display Java Version</title> 
</head> 
<body> 
<jsp:plugin code="com.applets.CheckJavaVersion" codebase="/AppletURLComm" type="applet"> 
</jsp:plugin> 
</body> 
</html> 

Now I want to access the javaversion variable in the JSP page. If I access that variable, it is giving null value. How to get the variable with value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2024-10-22 05:47:01

这与JSP无关。您想要获取驻留在客户端(小程序)上的变量。所以你必须使用 javascript 来完成此操作。 请参见此处此处

This has nothing to do with JSP. You want to obtain a variable that resides on the client (applet). So you have to do this with javascript. See here and here

九公里浅绿 2024-10-22 05:47:01
*package thumb;
/**
 * @author Ravi Thapa
 * @since May 20, 2014
 * @version 1.0 This class will get thumb impression image and verification
 * String
 */
public class ThumbVerification extends JApplet
        implements ActionListener {
        base64Image = null;
        base64FMR = null;
/*
here is code for thumb image capture code
*/

    public static byte[] decodeImage(String imageDataString) {
        return Base64.decodeBase64(imageDataString.getBytes());
    }
    public String getBase64FMR() {
        return base64FMR;
    }
    public String getBase64Image() {
        return base64Image;
    }
}

我编译了代码并转换为jar文件并签名

D:\Thumb\build\classes\thumb>keytool -genkey -keystore myKeystore -alias myself
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  Ravi 
What is the name of your organizational unit?
  [Unknown]:  abc
What is the name of your organization?
  [Unknown]:  abc
What is the name of your City or Locality?
  [Unknown]:  Lucknow
What is the name of your State or Province?
  [Unknown]:  UP
What is the two-letter country code for this unit?
  [Unknown]:  91
Is CN=Ravi Thapa, OU=NIC, O=NIC, L=Lucknow, ST=UP, C=91 correct?
  [no]:  yes
Enter key password for <myself>
        (RETURN if same as keystore password):
Re-enter new password:
D:\SECUGEN_DRIVERS\Thumb\build\classes\thumb>keytool -selfcert -alias myself -kystore myKeystore
Illegal option:  -kystore
keytool -selfcert [OPTION]...
Generates a self-signed certificate
Options:
 -alias <alias>                  alias name of the entry to process
 -sigalg <sigalg>                signature algorithm name
 -dname <dname>                  distinguished name
 -startdate <startdate>          certificate validity start date/time
 -validity <valDays>             validity number of days
 -keypass <arg>                  key password
 -storetype <storetype>          keystore type
 -keystore <keystore>            keystore name
 -storepass <arg>                keystore password
 -providername <providername>    provider name
 -providerclass <providerclass>  provider class name
 -providerarg <arg>              provider argument
 -providerpath <pathlist>        provider classpath
 -v                              verbose output
Use "keytool -help" for all available commands
D:\SECUGEN_DRIVERS\Thumb\build\classes\thumb>keytool -list -keystore myKeystore
Enter keystore password:
Keystore type: JKS
Keystore provider: SUN
Your keystore contains 1 entry
myself, Apr 15, 2014, PrivateKeyEntry,
Certificate fingerprint (SHA1): 24:9C:50:D7:49:47:27:EB:87:9A:BA:89:F4:19:72:6A:02:AF:1B:3F
D:\SECUGEN_DRIVERS\Thumb\build\classes\thumb>jarsigner -keystore myKeystore Thumb.jar myself
Enter Passphrase for keystore:
jar signed.
Warning:
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2014-07-14) or after any future revocation date.

将jar文件放入jsp文件中

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.File"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
        <meta http-equiv="cache-control" content="no-cache"/>
        <script type="text/javascript">
        function getVarData(){
                  var thumbImp = document.Applet1.getBase64FMR();
                  var thumbImpImage = document.Applet1.getBase64Image();
                  document.getElementById('varThumb').value = thumbImp;
                  document.getElementById('varThumbImage').value = thumbImpImage;
        }
        </script>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <applet code="thumb.ThumbVerification" width="120" height="170" id="Applet1" name="AppletABC"
                            archive="<%=request.getContextPath()%>/Thumb.jar"></applet>
                </td>
           </tr>
        </table>
    </body>
</html>
SEND THE DATA USING HIDDEN FIELD
 <input type="submit" value=" SAVE  " onclick="getVarData();"/>

               <input type="hidden" id="varThumb" name="varThumb"/>
               <input type="hidden" id="varThumbImage" name="varThumbImage"/>*
*package thumb;
/**
 * @author Ravi Thapa
 * @since May 20, 2014
 * @version 1.0 This class will get thumb impression image and verification
 * String
 */
public class ThumbVerification extends JApplet
        implements ActionListener {
        base64Image = null;
        base64FMR = null;
/*
here is code for thumb image capture code
*/

    public static byte[] decodeImage(String imageDataString) {
        return Base64.decodeBase64(imageDataString.getBytes());
    }
    public String getBase64FMR() {
        return base64FMR;
    }
    public String getBase64Image() {
        return base64Image;
    }
}

I compiled the code and convert into jar file and signed

D:\Thumb\build\classes\thumb>keytool -genkey -keystore myKeystore -alias myself
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  Ravi 
What is the name of your organizational unit?
  [Unknown]:  abc
What is the name of your organization?
  [Unknown]:  abc
What is the name of your City or Locality?
  [Unknown]:  Lucknow
What is the name of your State or Province?
  [Unknown]:  UP
What is the two-letter country code for this unit?
  [Unknown]:  91
Is CN=Ravi Thapa, OU=NIC, O=NIC, L=Lucknow, ST=UP, C=91 correct?
  [no]:  yes
Enter key password for <myself>
        (RETURN if same as keystore password):
Re-enter new password:
D:\SECUGEN_DRIVERS\Thumb\build\classes\thumb>keytool -selfcert -alias myself -kystore myKeystore
Illegal option:  -kystore
keytool -selfcert [OPTION]...
Generates a self-signed certificate
Options:
 -alias <alias>                  alias name of the entry to process
 -sigalg <sigalg>                signature algorithm name
 -dname <dname>                  distinguished name
 -startdate <startdate>          certificate validity start date/time
 -validity <valDays>             validity number of days
 -keypass <arg>                  key password
 -storetype <storetype>          keystore type
 -keystore <keystore>            keystore name
 -storepass <arg>                keystore password
 -providername <providername>    provider name
 -providerclass <providerclass>  provider class name
 -providerarg <arg>              provider argument
 -providerpath <pathlist>        provider classpath
 -v                              verbose output
Use "keytool -help" for all available commands
D:\SECUGEN_DRIVERS\Thumb\build\classes\thumb>keytool -list -keystore myKeystore
Enter keystore password:
Keystore type: JKS
Keystore provider: SUN
Your keystore contains 1 entry
myself, Apr 15, 2014, PrivateKeyEntry,
Certificate fingerprint (SHA1): 24:9C:50:D7:49:47:27:EB:87:9A:BA:89:F4:19:72:6A:02:AF:1B:3F
D:\SECUGEN_DRIVERS\Thumb\build\classes\thumb>jarsigner -keystore myKeystore Thumb.jar myself
Enter Passphrase for keystore:
jar signed.
Warning:
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2014-07-14) or after any future revocation date.

Put the jar file into jsp file

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.File"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
        <meta http-equiv="cache-control" content="no-cache"/>
        <script type="text/javascript">
        function getVarData(){
                  var thumbImp = document.Applet1.getBase64FMR();
                  var thumbImpImage = document.Applet1.getBase64Image();
                  document.getElementById('varThumb').value = thumbImp;
                  document.getElementById('varThumbImage').value = thumbImpImage;
        }
        </script>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <applet code="thumb.ThumbVerification" width="120" height="170" id="Applet1" name="AppletABC"
                            archive="<%=request.getContextPath()%>/Thumb.jar"></applet>
                </td>
           </tr>
        </table>
    </body>
</html>
SEND THE DATA USING HIDDEN FIELD
 <input type="submit" value=" SAVE  " onclick="getVarData();"/>

               <input type="hidden" id="varThumb" name="varThumb"/>
               <input type="hidden" id="varThumbImage" name="varThumbImage"/>*
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文