testconverter.java

来自「J2EE 技术 源码 书籍源代码(j2ee编程技术)」· Java 代码 · 共 58 行

JAVA
58
字号
/*
 * Created on 2004-9-17
 *
 * 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 aa
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class testConverter extends HttpServlet {
	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		//TODO Method stub generated by Lomboz
//		TODO Method stub generated by Lomboz
//		TODO Method stub generated by Lomboz
		response.setContentType("text/html");
		PrintWriter out =response.getWriter();
		out.println("<html><head><title>the first EJB</title></head>");
		try{
		InitialContext ctx=new InitialContext();
		Object objRef = ctx.lookup("ConverterBean");
//		主接口
		ConverterHome
		home=(ConverterHome)javax.rmi.PortableRemoteObject.narrow(
		objRef,ConverterHome.class);
//		组件接口
		Converter bean =home.create();
		out.println(bean.toLowerCase("HOW ARE YOU"));
		out.println(bean.toUpperCase("how are you"));
		}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);
		}
		out.println("</body></html>");

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?