Applet与JSP通讯 [英] Applet and JSP Communication

查看:152
本文介绍了Applet与JSP通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得它在客户端上的小程序加载后动态分配一个变量的值。小程序嵌入在JSP页面中。内的JSP页面中我想获得该值。来源$ C ​​$ c为如下:

 公共类CheckJavaVersion扩展的Applet
{
私有静态标签versionCheck;
公共静态字符串javaVersion;
公共无效的init()
{
尝试
{
颜色colFrameBackground =新的色彩(198,0,0);
this.setBackground(colFrameBackground);
versionCheck =新标签(Java版本:+ System.getProperty(java.version));
this.add(versionCheck);
javaVersion = versionCheck.getText();
}
}

JSP页:

 < HTML和GT;
< HEAD><标题>显示Java版本< /标题>
< /头>
<身体GT;
< JSP:插件code =com.applets.CheckJavaVersioncodeBase类=/ AppletURLCommTYPE =小程序>
< / JSP:插件>
< /身体GT;
< / HTML>

现在我要访问在JSP页面中的 javaversion 变量。如果我访问该变量,这是给值。如何与价值得到变量?


解决方案

  *包大拇指;
/ **
 * @author拉维·塔帕
 * @since 2014年5月20日
 * @version 1.0级将获得拇指IM pression形象和验证
 *字符串
 * /
公共类ThumbVerification扩展JApplet的
        实现ActionListener的{
        base64Image = NULL;
        base64FMR = NULL;
/ *
这里是code拇指图像采集code
* /    公共静态的byte []德$ C $的CImage(字符串imageDataString){
        返回Base64.de codeBase64(imageDataString.getBytes());
    }
    公共字符串getBase64FMR(){
        返回base64FMR;
    }
    公共字符串getBase64Image(){
        返回base64Image;
    }
}

我编译code和转换成jar文件,并签署

  D:\\拇指\\编译\\类\\拇指>的keytool -genkey -keystore myKeystore -alias自己
输入密钥库密码:
重新输入新密码:
什么是你的名和姓?
  [未知]:拉维
什么是您的组织单位的名称?
  [未知]:ABC
什么是您的组织的名称?
  [未知]:ABC
您所在的城市或地区的名字吗?
  [未知]:勒克瑙
您所在的州或省的名称是什么?
  [未知]:UP
什么是两个字母的国家code这个单位?
  [未知]:91
是CN =拉维·塔帕,OU =网卡,O =网卡,L =勒克瑙,ST = UP,C = 91正确吗?
  [否]:是
为&LT键输入密码;我自己>
        (返回,如果相同的密钥库的密码):
重新输入新密码:
D:\\ SECUGEN_DRIVERS \\拇指\\编译\\类\\拇指>密钥工具-selfcert -alias自己-kystore myKeystore
非法选项:-kystore
密钥工具-selfcert [选项] ...
生成自签名证书
选项​​:
 -alias<&别名GT;条目的别名处理
 -sigalg< sigalg>签名算法名
 -dname<&DNAME GT;专有名称
 -startdate<&STARTDATE GT;证书有效期起始日期/时间
 -validity< valDays>天的有效号码
 -keypass<&ARG GT;密钥密码
 -storetype<&的storetype GT;密钥库类型
 -keystore<&密钥存储GT;密钥库名称
 -storepass<&ARG GT;密钥库密码
 -providerName<&的providerName GT;提供程序名称
 -providerclass< providerclass>提供程序类名
 -providerarg<&ARG GT;供应商的说法
 -providerpath< pathlist>供应商类路径
 -v详细输出
使用的keytool -help所有可用命令
D:\\ SECUGEN_DRIVERS \\拇指\\编译\\类\\拇指>的keytool -list -keystore myKeystore
输入密钥库密码:
密钥库类型:JKS
密钥库提供:SUN
您的密钥存储库包含1项
我自己,2014年4月15日,PrivateKeyEntry,
证书指纹(SHA1):24:9C:50:D7:49:47:27:EB:87:9A:BA:89:F4:19:72:6A:02:AF:1B:3F
D:\\ SECUGEN_DRIVERS \\拇指\\编译\\类\\拇指>的jarsigner -keystore myKeystore Thumb.jar自己
输入口令密钥库:
罐子签署。
警告:
签名证书将在六个月内到期。
没有-tsa或-tsacert提供这个罐子是不是时间戳。如果没有时间戳,用户可能无法验证签名证书的截止日期(2014年7月14日)之后,或任何未来的撤销日期之后这个瓶子。

把jar文件到JSP文件

 <%@页语言=Java的的contentType =text / html的;字符集= UTF-8的pageEncoding =UTF-8%>
<%@页面进口=java.io.File中的%>
< HTML和GT;
    < HEAD>
        < META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= UTF-8>< /元>
        < META HTTP-EQUIV =缓存控制内容=无缓存/>
        <脚本类型=文/ JavaScript的>
        功能getVarData(){
                  变种thumbImp = document.Applet1.getBase64FMR();
                  变种thumbImpImage = document.Applet1.getBase64Image();
                  。的document.getElementById('varThumb')值= thumbImp;
                  。的document.getElementById('varThumbImage')值= thumbImpImage;
        }
        < / SCRIPT>
    < /头>
    <身体GT;
        <表>
            &所述; TR>
                &所述; TD>
                    <小程序code =thumb.ThumbVerificationWIDTH =120HEIGHT =170ID =Applet1NAME =AppletABC
                            归档=<%= request.getContextPath()%GT; /Thumb.jar>< /小程序>
                < / TD>
           < / TR>
        < /表>
    < /身体GT;
< / HTML>
发送使用隐藏字段中的数据
 <输入类型=提交值=SAVE的onclick =getVarData();/>               <输入类型=隐藏ID =varThumbNAME =varThumb/>
               <输入类型=隐藏ID =varThumbImageNAME =varThumbImage/> *

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?

解决方案

*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"/>*

这篇关于Applet与JSP通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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