ejb轻松进阶
第四步 编写客户代码
便完了ejb代码,下面我们来写客户代码。
1、mysecurityjsp.html文件用于显示一个静态的网页,它提供了用户录入明文/密文的界面,使用户能够录入自己的内容然后提交给服务器端。其源代码如下:
文件mysecurityjsp.html
< html >
< head >
< title >ejb示例:数据加密、解密演示系统< /title >
< /head >
< body background="bg.gif" >
< center >
< h1 >数据加密解密演示系统< img src="duke.gif" >< /h1 >
< br >< br >< br >
< form method="get" action="securityjspalias" >
< table width="700" height="300" border="1" >
< tr >
< td align="center" >
< h2 >――加密请求窗――< /h2 >
< p >
请输入明文:
< p >
< input type="text" name="sourcecontent" >< /input >
< p >
< input type="submit" value=" 提 交 " >
< input type="reset" value=" 重 置 " >
< /td >
< td align="center" >
< h2 >――解密请求窗――< /h2 >
< p >
请输入密文:
< p >
< input type="text" name="targetcontent" >< /input >
< p >
< input type="submit" value=" 提 交 " >
< input type="reset" value=" 重 置 " >
< /td >
< /tr >
< /table >
< /form >
< /center >
< /body >
< /html >
2、securityprocesspage.jsp文件是用jsp编写的动态网页,它用于处理mysecurityjsp.html提交过来的内容,并查找、生成ejbhome对象,发送加密/解密请求,并将结果传回客户端。其源代码如下:
文件“securityprocesspage.jsp”
< %@ page language="java" info="数据加密解密信息处理系统" % >
< %@ page import="java.rmi.*" % >
< %@ page import="javax.naming.*" % >
< %@ page import="javax.rmi.portableremoteobject" % >
< %@ page import="securitybeans.*" % >
< html >
< head >
< title >ejb示例:数据加密、解密演示系统< /title >
< /head >
< %
securityhome shmain = null;
try
{
shmain = ( securityhome )portableremoteobject.narrow( new initialcontext().lookup( "mysecurity" ), securityhome.class );
}//try
catch( namingexception ne )
{
ne.printstacktrace();
}//catch
security security = shmain.create();
% >
< body background="bg.gif" >
< center >
< h1 >数据加密解密演示系统< img src="duke.gif" >< /h1 >< br >< br >< br >
< table width="700" height="300" border="1" >
< tr >
< td align="center" >
< %
if ( request.getparameter( "sourcecontent" ) != null )
{
% >
加密生成的密文为:< br >
< %= security.encrypt( request.getparameter( "sourcecontent" ) ) % >
< %
}//if
% >
< /td >
< td align="center" >
< %
if ( request.getparameter( "targetcontent" ) != null )
{
% >
解密生成的明文为:< br >
< %= security.encrypt( request.getparameter( "targetcontent" ) ) % >
< %
}//if
% >
< /td >
< /tr >
< /table >
< /center >
< /body >
< /html >
第四步 编写客户代码
便完了ejb代码,下面我们来写客户代码。
1、mysecurityjsp.html文件用于显示一个静态的网页,它提供了用户录入明文/密文的界面,使用户能够录入自己的内容然后提交给服务器端。其源代码如下:
文件mysecurityjsp.html
< html >
< head >
< title >ejb示例:数据加密、解密演示系统< /title >
< /head >
< body background="bg.gif" >
< center >
< h1 >数据加密解密演示系统< img src="duke.gif" >< /h1 >
< br >< br >< br >
< form method="get" action="securityjspalias" >
< table width="700" height="300" border="1" >
< tr >
< td align="center" >
< h2 >――加密请求窗――< /h2 >
< p >
请输入明文:
< p >
< input type="text" name="sourcecontent" >< /input >
< p >
< input type="submit" value=" 提 交 " >
< input type="reset" value=" 重 置 " >
< /td >
< td align="center" >
< h2 >――解密请求窗――< /h2 >
< p >
请输入密文:
< p >
< input type="text" name="targetcontent" >< /input >
< p >
< input type="submit" value=" 提 交 " >
< input type="reset" value=" 重 置 " >
< /td >
< /tr >
< /table >
< /form >
< /center >
< /body >
< /html >
2、securityprocesspage.jsp文件是用jsp编写的动态网页,它用于处理mysecurityjsp.html提交过来的内容,并查找、生成ejbhome对象,发送加密/解密请求,并将结果传回客户端。其源代码如下:
文件“securityprocesspage.jsp”
< %@ page language="java" info="数据加密解密信息处理系统" % >
< %@ page import="java.rmi.*" % >
< %@ page import="javax.naming.*" % >
< %@ page import="javax.rmi.portableremoteobject" % >
< %@ page import="securitybeans.*" % >
< html >
< head >
< title >ejb示例:数据加密、解密演示系统< /title >
< /head >
< %
securityhome shmain = null;
try
{
shmain = ( securityhome )portableremoteobject.narrow( new initialcontext().lookup( "mysecurity" ), securityhome.class );
}//try
catch( namingexception ne )
{
ne.printstacktrace();
}//catch
security security = shmain.create();
% >
< body background="bg.gif" >
< center >
< h1 >数据加密解密演示系统< img src="duke.gif" >< /h1 >< br >< br >< br >
< table width="700" height="300" border="1" >
< tr >
< td align="center" >
< %
if ( request.getparameter( "sourcecontent" ) != null )
{
% >
加密生成的密文为:< br >
< %= security.encrypt( request.getparameter( "sourcecontent" ) ) % >
< %
}//if
% >
< /td >
< td align="center" >
< %
if ( request.getparameter( "targetcontent" ) != null )
{
% >
解密生成的明文为:< br >
< %= security.encrypt( request.getparameter( "targetcontent" ) ) % >
< %
}//if
% >
< /td >
< /tr >
< /table >
< /center >
< /body >
< /html >
闽公网安备 35060202000074号