+

Search Tips   |   Advanced Search

 

Example: Locating resources in two different contexts using the framework programming model

 

The Framework Programming Model for including resources remotely does not require you to use any non-J2EE Servlet Application Programming Interfaces (APIs). When a request is initiated for a ServletContext name that is not presently running inside of the current Web container, the remote request dispatcher (RRD) component returns a ServletContext object that can locate a resource that exists anywhere inside a WebSphere Application Sever ND environment provided that the resource exists and RRD is enabled for that ServletContext object. Study the following sample framework snippet that demonstrates how to locate resources located in two different contexts, investments and banking.

/*
Programming example using a generic framework.
Servlet Specification provides an API to obtain  a servlet context in the scope of the same request different from the current Web module context by specifying a context parameter.

Servlet Specification restriction: The Web module that obtain must run inside of the same JVM as the calling resource.

RRD extends this functionality by permitting the Web module to be located within the scope of the current core group  versus the scope of the JVM.

*/
 protected void frameworkCall (ServletContext context, HttpServletRequest request, HttpServletResponse response) 
              throws ServletException, IOException(

      PrintWriter writer = response.getWriter();

      writer.write("<HTML>");
      writer.write("<HEAD>");
      writer.write("</HEAD>");
      writer.write("<BODY>");
      writer.write("<hr size=\"5/">);

      //Include resource investmentSummary.jsp located in Web application
      //with context root of /investments.
      RequestDispatcher rd = getRequestDispatcher ( context, "/investments", "/investmentSummary.jsp");
      rd.include(request, response);

      writer.write("<hr size=\"5/">);

      //Include resource accountSummary.jsp located in Web application
      //with context root of /banking.
      rd = getRequestDispatcher ( context, "/banking", "/accountSummary.jsp");
      rd.include(request, response);

      writer.write("</BODY>");
      writer.write("</HTML>");
} private RequestDispatcher getRequestDispatcher (ServletContext context, String contextName, String resource) {
      return context.getContext(contexName).getRequestDispatcher(resource);
}



 

Related tasks


Task overview: Assembling applications using remote request dispatcher
Configure Web applications to dispatch remote includes
Configure Web applications to service remote includes

 

Related Reference


Example: Locating resources in two different contexts using the Servlet programming model

 

Reference topic