WEB开发网
开发学院软件开发Java 用Cactus来测试J2ee应用 阅读

用Cactus来测试J2ee应用

 2010-03-19 00:00:00 来源:WEB开发网   
核心提示: 接下来是访问EJB的客户端,我们用了一个servlet.ManaServlet.javapackageusersystem.servlet;importjavax.servlet.*;importjavax.servlet.http.*;importjava.io.*;importjava.ut

接下来是访问EJB的客户端,我们用了一个servlet.

ManaServlet.java 
package usersystem.servlet; 
import javax.servlet.*; 
import javax.servlet.http.*; 
import java.io.*; 
import java.util.*; 
import usersystem.*; 
import javax.naming.*; 
import javax.ejb.*; 
import javax.ejb.*; 
import javax.ejb.*; 
/** 
 * <p>Title: </p> 
 * <p>Description: </p> 
 * <p>Copyright: Copyright (c) 2002</p> 
 * <p>Company: </p> 
 * @author unascribed 
 * @version 1.0 
 */ 
public class ManaServlet extends HttpServlet { 
  static final private String CONTENT_TYPE = "text/html; charset=GBK"; 
  private UserManagerLocalHome h=null; 
  private UserManagerLocal uml=null; 
  public void init() throws ServletException{ 
    try { 
      h=getHome(); 
      uml=h.create() ; 
    } 
    catch (CreateException ex) { 
      ex.printStackTrace() ; 
    } 
  } 
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws 
ServletException, IOException { 
  } 
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws 
ServletException, IOException { 
  } 
  public void addUser(HttpServletRequest request, HttpServletResponse response) throws 
javax.ejb.EJBException { 
    String name=request.getParameter("name") ; 
    String tel=request.getParameter("tel") ; 
    String address=request.getParameter("address") ; 
    String email=request.getParameter("email") ; 
    String pass=request.getParameter("pass") ; 
    uml.addUser(name,pass,email,address,tel) ; 
  } 
  public User findByName(String name) throws javax.ejb.EJBException { 
    User u = null; 
    u=uml.findByName(name) ; 
    return u; 
  } 
  public java.util.Iterator findAll() throws javax.ejb.EJBException { 
    java.util.Collection c=uml.findAll() ; 
    return c.iterator() ; 
  } 
  public void delAll() throws javax.ejb.EJBException { 
    uml.delAll() ; 
  } 
  public void delUser(String name) throws javax.ejb.EJBException { 
      uml.delByName(name) ; 
  } 
  public UserManagerLocalHome getHome() { 
    UserManagerLocalHome home = null; 
    try { 
      javax.naming.InitialContext ctx=new javax.naming.InitialContext (); 
      home=(UserManagerLocalHome)ctx.lookup("UserManagerLocal") ; 
    } 
    catch (NamingException ex) { 
      ex.printStackTrace() ; 
      return null; 
    } 
    return home; 
  } 
  public void destroy() { 
  } 
} 

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:Cactus Jee

编辑录入:爽爽 [复制链接] [打 印]
    赞助商链接