Java Reference
In-Depth Information
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
You have seen many examples of how the
out
object is used. It is used to write into the output
stream that is delivered back to the client. The most common use is to use the
out.println()
method, passing it HTML text that will be displayed in the client's browser. Most of your out-
put will be presented to the client in the
out.println()
method. Listing 15.5 contains an
example of how you use the implicit
out
object.
L
ISTING
15.5
UseOut.jsp
<%@ page errorPage=”errorpage.jsp” %>
<html>
<head>
<title>Use Out</title>
</head>
<body>
<%
// Print a simple message using the implicit out object.
out.println(“<center><b>Hello!</b></center>”);
%>
</body>
</html>
Copy this file to the
<
SERVER_ROOT
>/djs/
directory and then open your browser to the follow-
ing URL:
http://
localhost
/djs/UseOut.jsp
You should now see a page similar to Figure 15.4.
The
config
Object
The implicit
config
object represents the
ServletConfig
, which defines a servlet-engine-
generated object that contains configuration information. The configuration information that
this servlet will have access to is the
ServletContext
object, which describes the context
within which the generated servlet will be running. You can see how the
config
object is ini-
tialized in the following code snippet:
ServletConfig config = null;
JspWriter out = null;
Object page = this;