8.1. Quick Introduction to Servlets
According to Java Servlet Programming, 2nd Edition—O'Reilly
A servlet is a generic server extension—a Java class that can be loaded dynamically to expand the func-
tionality of a server. Servlets are commonly used with web servers, where they can take the place of CGI
scripts.
Servlets are executed inside a Java Virtual Machine. The official reference implementation and most
commonly used servlet container is Apache's Tomcat Server, which is packaged with Red Hat Appli-
cation Server and is also freely available from the Apache web site http://jakarta.apache.org.
Servlet/JSP engines are embedded in J2EE
8.2. Retrieving a Home Interface and Creating a Bean
Here is an example on how to retrieve the home interface of a bean named Region from a Servlet and
then create a new instance of this bean:
import java.io.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.*;
import javax.servlet.http.*;
public class RegionServlet extends HttpServlet
{
/**
* Called on a GET request for this servlet
*
* @param request a
* @param response a
* @exception IOException if an error occurs
* @exception ServletException if an error occurs
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException
{
private PrintWriter out;
response.setContentType("text/html");
try
{
out = reponse.getWriter();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
out.println("
Accessing Beans From a Servlet
TM
code
HttpServletRequest
¥
¦
code
HttpServletResponse
¥
¦
!doctype html public
¥
servers. Red Hat Application Server supports Tomcat.
/code
¥
Chapter 8.
value
¦
/code
value
¥
¦
Need help?
Do you have a question about the APPLICATION SERVER - JONAS and is the answer not in the manual?
Questions and answers