Cover | Table of Contents | Colophon
ServletContext. We
refer to JSPs and servlets as web components.
These web components also have access to external resources and
WebLogic enterprise services such as deployed EJB components, JDBC
data sources, JMS destinations, XML parser factories, and much more
through access to ServletContext.getResource() and getResourceAsStream( ) of the ServletContext object and the
forward( ) and include( )
methods of the RequestDispatcher object can access
the contents of the WEB-INF
folder.
session-timeout element within the standard
web.xml deployment descriptor.here, you could access it by
using a URL of the form http://server:port/here/index.html. If you do
not explicitly set a context root for the web application, its
default value depends on how the web application has been packaged:context-root element within the
weblogic.xml descriptor for the web
application:
<weblogic-web-app> <context-root>
dispatch-policy
element for the servlet. The value of this element should match the
name of a preconfigured execute queue. Here is an example:<servlet-descriptor>
<servlet-name>FooServlet</servlet-name>
<init-as-principal-name>system</init-as-principal-name>
<destroy-as-principal-name>system</destroy-as-principal-name>
<dispatch-policy>MyCustomExecuteQ</dispatch-policy>
</servlet-descriptor>taglib
element in the standard web.xml deployment
descriptor:<taglib>
<taglib-uri>/weblogic-tags</taglib-uri>
<taglib-location>/WEB-INF/lib/weblogic-tags.jar</taglib-location>
</taglib> <%@ taglib uri="/weblogic-tags" prefix="wl" %>cache
tag enables you to cache the output generated within the
body of the tag. Because the output is usually some function of
parameter or attribute values, the tag also allows you to cache the
values of input parameters or attributes that uniquely generate a
particular response. The caches are implemented using soft references
to prevent the cache mechanism from hogging memory.
Let's examine important attributes of the
cache tag.cache tag may specify a unique
name for the cache, if it is to be used across
multiple JSP pages. A random name is generated if you do not specify
one. By default, the HttpSession object allows servlets and JSPs to
manage client-specific state on the server. You can associate
object-valued attributes to the HttpSession by
name. Any object bound to the session is available to any other
servlet within the same servlet context. You can even declare
JavaBean components within JSPs that have session-wide
scope.
HttpSession is created, a unique ID is associated
with it. WebLogic then attempts to store the session ID by sending a
cookie back to the client. Once a cookie is set, the browser will
return the cookie on each subsequent request. The server then is able
to parse the cookie and return the associated session object when you
invoke the getSession( ) method on the servlet.
The servlet specification demands that this session-tracking cookie
be named JSESSIONID.java.io.Serializable
interface before it can be bound in the session. If you have
configured session persistence to use cookies instead, only strings
may be bound in the HTTP session.replicated enables WebLogic to replicate the
session state in memory itself. Like the default memory persistence
scheme, session data is stored in memory. Unlike the default memory
persistence, this scheme works closely with the notion of primary and
secondary servers in the cluster, as discussed later in Chapter 14. WebLogic creates the primary session state
on the server that a client first connects to, and then transparently
replicates the session-state information onto a secondary server
instance. The process of copying session state from one server
instance to another in the cluster is called in-memory
replication. The replica is kept up-to-date so that the
secondary server can take over when the original server instance that
holds the session data fails.
Serializable
objects. Changes to the session object will be replicated only if you
use the setAttribute( ) and
removeAttribute( ) methods on the
HttpSession object. These methods ensure that any
changes to the attributes of the session are mirrored onto the
secondary server for the client. Remember that only nontransient
attributes of an object in the session will be replicated to the
secondary server. All transient attributes of the object will be
ignored.HttpSession session = request.getSession(false);
com.oreilly.user.AUser foo = (AUser) session.getAttribute("user");
foo.setName("Ali Cowan");AUser object will be replicated
only if you subsequently invoke the setAttribute(
) method:session.setAttribute("user", foo);setAttribute( )HttpClusterServlet
HttpClusterServlet is an alternative to a
proxy plug-in. A WebLogic instance can be configured to host the
servlet, which can forward requests across to the cluster in the same
way as the proxy plug-in.HttpClusterServlet, leaving the configuration of
the proxy plug-ins, an almost identical task, to Chapter 3.HttpClusterServlet is a
servlet. It is supplied with WebLogic. To put the servlet into
action, create a simple web application with the servlet configured
as part of the web application. You need to then deploy the web
application to the machine that is going to serve as the main gateway
to your cluster, as suggested by Figure 2-2.
login-config element in the standard
web.xml deployment descriptor allows you to set
up authentication for a web application. You can specify the
authentication method using the auth-method
element. WebLogic supports the following authentication methods:BASIC)FORM)<form method="post" action="j_security_check"> <input type="text" name="j_username"> <input type="password" name="j_password"> </form>
form-login-page subelement to specify the login
page, and the form-error-page subelement to
specify the error page.<!-- web.xml entry: -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>foo</realm-name>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/error.html</form-error-page>
</form-login-config>
</login-config>CLIENT-CERT)/* is the
FileServlet, which serves any request for static
files. JSPs also are listed here because they, too, are servlets.|
Parameter
|
Description
|
Default
|
|---|---|---|
|
Default Server Name
|
Sets the hostname returned in the HTTP response header when the web
server redirects a request.
|
none
|
|
Enable Keepalives
|
Use this to set HTTP keepalives. You generally want this set to
true. |
true
|
|
Duration
|
The number of seconds to wait before closing an inactive HTTP
connection.
|
30
|
|
HTTPS Duration
|
The number of seconds to wait before closing an inactive HTTPS
connection.
|
60
|
v1 and
v2.|
Parameter
|
Description
|
Default
|
|---|---|---|
|
Enabled HTTP Logging
|
This setting enables logging of HTTP requests for the particular
server or virtual host.
|
true
|
|
Log File Name
|
This setting determines the filename to which the log messages are
written. If you provide a relative filename, it is assumed to be
relative to the root directory of the machine on which the server or
virtual host is running. |
InitialContext
representing the context root of the server's
directory service. You can do this by passing a
Hashtable of property/value pairs to the
javax.naming.InitialContext( ) constructor. The
Hashtable represents environment properties that
are used to establish the context; in an external client, you
typically will need to supply at least a URL property that points to
a server you wish to access, and a context factory class that
represents the service provider to use in the construction of the
context.
import javax.naming.*;
private static InitialContext ctx = null;
...
public static InitialContext getInitialContext( ) throws NamingException {
if (ctx == null) {
Hashtable env = new Hashtable( );
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context ctx = null;
Hashtable env = new Hashtable( );
env.put(Context.INITIAL_CONTEXT_FACTORY,
weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://mycluster:8001");
//connect to the cluster-wide JNDI tree
ctx = new InitialContext(env);
//now use the JNDI Context to look up objectsPROVIDER_URL
property uses the DNS name mycluster, which
resolves to the addresses of each server in the cluster.