QA

Q&A

Q1:

In servlet chaining, if the servlet to which the request is to be delegated is not loaded that is, not active in the WebLogic Server what will happen?

A1:

If the servlet to which the request is forwarded is not active in the WebLogic Server, the ServletContext object's method getServlet(servletname) will return a null object reference. To safeguard against this scenario, the calling servlet should check whether the called servlet object's reference is valid. In a scenario where the called servlet is not active, the calling servlet can still forward the request to the called servlet in a roundabout way. The calling servlet is allowed to open socket connections. Hence, it can open a java.net.URLConnection() object that passes the URL of the servlet to be called as the parameter. The IP address in this case will be localhost or 127.0.0.1 since both the servlets reside on the same machine. Opening a URL connection to the called servlet's URL makes the WebLogic Server load (that is, activate) this servlet. Now, when the calling servlet tries to obtain the called servlet's object reference using the ServletContext, it will not get a null reference!

Q2:

Can a filter for an HTTP servlet modify the headers available in the HTTP request and response?

A2:

Most certainly it can. A filter should be used primarily for preprocessing the HttpServletRequest and HttpServletResponse for a servlet. Hence, the filter can modify the request and response headers. For example, if your servlet does not contain session-handling code, the filter can insert cookies in the response headers and can read the cookies in the request headers. Thus, the filter can take over the responsibility of maintaining user sessions and can terminate a logical user session by not delegating control to the next chain of filters or to the servlet itself. This is especially useful when you wish to reuse servlet classes without having to modify the source code of the servlet.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net