利用 WebSphere Process Server 7 轻松定做属于自己的 EJB service
2010-05-21 00:00:00 来源:WEB开发网这段代码首先会根据前面所创建的 EJB 服务的 JNDI 名用代码 initialContext.lookup(jndiName)来查找其所对应该 Service 的对象,随后再用代码 (EJB3RemoteTwoWay) javax.rmi.PortableRemoteObject.narrow(ejbBusIntf,EJB3RemoteTwoWay.class)
来获得该 EJB Service 所对应的业务接口(在本文案例中为 EJB3RemoteTwoWay), 也就是前面定义 EJB3.0 Remote Export Binding 时所采用的接口。然后,再用代码 busI.e3Remotetwoway(customer)来调用该 EJB3.0 Export Binding 服务。
在 WebContent 目录下,新建 JSP 文件 EJBTest.jsp 作为用户输入终端界面,并写入如下代码:
清单 3. EJB Test JSP 的代码片断
<%@ page language="java"contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=ISO-8859-1">
<title>Test invoke EJB export</title>
</head>
<body>
<form action="TestInput.jsp"method="get">
<fieldset><legend>Enter Customer Info: </legend>
<br>Customer Info <input type="text"name="cusInfo">
</fieldset>
<input type="submit"value="submit"><br>
</form>
<%
/**
* Set request character encoding and response caracter encoding to UTF-8
* It must be put ahead the jsp file.
* Since if any characters have been printed on page,
* the encoding set action will be no use.
*/
try{
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
}catch(java.lang.Exception e){
e.printStackTrace();
}
%>
<%
try{
String tcInput=request.getParameter("cusInfo");
if(tcInput != null) {
EJBExportInvoker.invokeEJB3RemoteWsdlTwoWayExport(tcInput);
}
} catch(Exception e){
out.println("UnExpectedException: " + e.getMessage());
e.printStackTrace(System.out);
}
%>
</body>
</html>
更多精彩
赞助商链接