img
Notice how the header keys and values are displayed. First, a map of the header keys and
values is obtained by calling getHeaderFields( ) (which is inherited from URLConnection).
Next, a set of the header keys is retrieved by calling keySet( ) on the map. Then the key set
is cycled through by using a for-each style for loop. The value associated with each key is
obtained by calling get( ) on the map.
The URI Class
A relatively recent addition to Java is the URI class, which encapsulates a Uniform Resource
Identifier (URI). URIs are similar to URLs. In fact, URLs constitute a subset of URIs. A URI
represents a standard way to identify a resource. A URL also describes how to access the
resource.
Cookies
The java.net package includes classes and interfaces that help manage cookies and can be used
to create a stateful (as opposed to stateless) HTTP session. The classes are CookieHandler,
CookieManager, and HttpCookie. The interfaces are CookiePolicy and CookieStore. All but
CookieHandler was added by Java SE 6. (CookieHandler was added by JDK 5.) The creation of a
stateful HTTP session is beyond the scope of this topic.
NOTE  For information about using cookies with servlets, see Chapter 31.
OTE
TCP/IP Ser ver Sockets
As mentioned earlier, Java has a different socket class that must be used for creating server
applications. The ServerSocket class is used to create servers that listen for either local or
remote client programs to connect to them on published ports. ServerSockets are quite
different from normal Sockets. When you create a ServerSocket, it will register itself with
the system as having an interest in client connections. The constructors for ServerSocket
reflect the port number that you want to accept connections on and, optionally, how long
you want the queue for said port to be. The queue length tells the system how many client
connections it can leave pending before it should simply refuse connections. The default is
50. The constructors might throw an IOException under adverse conditions. Here are three
of its constructors:
Ser verSocket(int por t) throws IOException
Creates ser ver socket on the specified por t
with a queue length of 50.
Ser verSocket(int por t, int maxQueue)
Creates a ser ver socket on the specified por t
with a maximum queue length of maxQueue.
throws IOException
Ser verSocket(int por t, int maxQueue,
Creates a ser ver socket on the specified por t
InetAddress localAddress)
with a maximum queue length of maxQueue.
On a multihomed host, localAddress specifies
throws IOException
the IP address to which this socket binds.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home