Java Tutorial - Java Scipt :
The TestUserEJB Servlet
The next step is to create a servlet that uses the UserDelegate class. The source code for the servlet follows:
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oldfriends.user.*;
import javax.ejb.*;
public class TestUserEJB extends HttpServlet
{
protected void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
UserDelegate ud;
try
{
ud = new UserDelegate();
UserDTO udata =
ud.getUserByUserid(“0000000-000000-00000000-0-00000000-1”);
out.println(“Hello:”+ud.getHello());
out.println( “Name:”+
udata.getFirstName() + “ “ +
udata.getLastName()+” “+udata.getUserid());
}
catch( Exception e )
{
e.printStackTrace(out);
}
}
}
Note that the servlet has no knowledge that the actual implementation of UserDelegate occurs via an EJB.