📄 teststatefulaccount.java
字号:
/*
* Created on 2004-4-5
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.ejbstudy;
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
/**
* @author 郝玉龙
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class TestStatefulAccount extends HttpServlet {
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
//TODO Method stub generated by Lomboz
response.setContentType("text/html");
PrintWriter out =response.getWriter();
out.println("<html><head><title>the Stateful EJB Test</title></head>");
try{
InitialContext ctx=new InitialContext();
Object objRef = ctx.lookup("StatefulAccountBean");
// 主接口
StatefulAccountHome
home=(StatefulAccountHome)javax.rmi.PortableRemoteObject.narrow(
objRef,StatefulAccountHome.class);
// 组件接口
StatefulAccount account =home.create(500.00);
out.println("the account balance:"+account.getBalance()+"<br>");
// 向基金帐户增加5000.25
account.depoist(2389.25);
out.println("method of depoist(2389.25) Result:"+account.getBalance()+"<br>");
// 从基金帐户调出1000.02
account.withdraw(1000.02);
out.println("method of withdraw(1000.02) Result:"+account.getBalance());
out.println("<hr>");
out.println("current account balance:"+account.getBalance());
account=null;
}catch(javax.naming.NamingException ne){
out.println("Naming Exception caught:"+ne);
ne.printStackTrace(out);
}catch(javax.ejb.CreateException ce){
out.println("Create Exception caught:"+ce);
ce.printStackTrace(out);
}catch(java.rmi.RemoteException re){
out.println("Remote Exception caught:"+re);
re.printStackTrace(out);
}
catch(Exception e){
out.println("Remote Exception caught:"+e);
e.printStackTrace(out);
}
out.println("</body></html>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -