3.4 Accessing the Servlet Context
In rare situations, a report intended to be run only in a web environments may need to access the servlet context or configuration parameters. To do this, use the ServletRepository class:
Servlet servlet = ServletRepository.getServlet();
ServletConfig config = servlet.getServletConfig();
ServletContext context = config.getServletContext();
However, there are several disadvantages of accessing the servlet in a replet class:
• If a report accesses the servlet instance, it can only be used in a web environment.
• The repository must be run locally in the servlet. It is impossible to use a remote repository server using either RMI or CORBA.
HTTP Request and Response
When a report is running inside a servlet, the HTTP request and response objects are accessible as special parameters in the replet request. You can retrieve these from the HttpServiceRequest and HttpServiceResponse objects using the RepletRequest constants SERVICE_REQUEST and SERVICE_RESPONSE.
// param is the RepletRequest object passed to
// createReport()
HttpServiceRequest srvreq = (HttpServiceRequest) param.getParameter(RepletRequest.SERVICE_REQUEST);
HttpServletRequest srvreq.getRequest();
HttpServiceResponse srvres = (HttpServiceResponse)
param.getParameter(RepletRequest.SERVICE_RESPONSE);
HttpServletResponse resp = srvres.getResponse();
These parameters are not accessible if the report is not running inside a servlet. The ability to access the HTTP request object is designed only to satisfy some special needs in the Web environment, such as access to the session object. It should not be used to access the report parameters.
| << 3.3 Managing the Data Repository (datasource.xml) | © 1996-2013 InetSoft Technology Corporation (v11.5) | 3.5 Pooling Database Connections Programmatically >> |