Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
17.4 A Query Viewer That Uses Object Serialization and HTTP Tunneling
443
2. Create an
ObjectOutputStream
.
ObjectOutputStream out =
new ObjectOutputStream(response.getOutputStream());
3. Write the data structure by using
writeObject
. Most
built in data structures can be sent this way. Classes you write,
however, must implement the
Serializable
interface. This is
a simple requirement, however, since
Serializable
defines no
methods. Simply declare that your class implements it.
SomeClass value = new SomeClass(...);
out.writeObject(value);
4. Flush the stream to be sure all content has been sent to
the client.
out.flush();
The following section gives an example of this approach.
17.4 A Query Viewer That Uses
Object Serialization and
HTTP Tunneling
Many people are curious about what types of queries are sent to the major
search engines. This is partly idle curiosity ( Is it really true that 64 percent of
the queries at AltaVista are from employers looking for programmers that
know Java technology? ) and partly so that HTML authors can arrange their
page content to fit the types of queries normally submitted, hoping to
improve their site's ranking with the search engines.
This section presents an applet/servlet combination that displays the ficti
tious
super search engine.com
live, continually updating sample que
ries to visitors that load their query viewer page. Listing 17.4 shows the main
applet, which makes use of an auxiliary class (Listing 17.5) to retrieve the
queries in a background thread. Once the user initiates the process, the
applet places a sample query in a scrolling text area every half second, as
shown in Figure 17 3. Finally, Listing 17.6 shows the servlet that generates
the queries on the server. It generates a random sampling of actual recent
user queries and sends 50 of them to the client for each request.
If you download the applet and servlet source code from
http://www.coreservlets.com/
and try this application yourself, be
aware that it will only work when you load the top level HTML page by using
Home page for this book: www.coreservlets.com; Home page for sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved