Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
17.2 A Multisystem Search Engine Front End
435
encode the value of each entry, but not the equal sign (=) between each entry
name and its value or the ampersand (&) between each name/value pair. So,
you cannot necessarily simply call 
URLEncoder.encode(someData)
 but
instead need to selectively encode the value parts of each name/value pair. This
could be accomplished as follows:
String someData =
name1 + "=" + URLEncoder.encode(val1) + "&" +
name2 + "=" + URLEncoder.encode(val2) + "&" +
...
nameN + "=" + URLEncoder.encode(valN);
try {
URL programURL = new URL(baseURL + "?" + someData);
getAppletContext().showDocument(programURL);
} catch(MalformedURLException mue) { ... }
The following section gives a full fledged example.
17.2 A Multisystem Search Engine 
Front End
In Section 6.3 (A Front End to Various Search Engines), the 
SearchSpec
class (Listing 6.2) was used by a servlet to generate the specific URLs
needed to redirect requests to various different search engines. The
SearchSpec
 class can be used by applets as well. Listing 17.1 shows an
applet that creates a textfield to gather user input. When the user submits
the data, the applet URL encodes the textfield value and generates three
distinct URLs with embedded 
GET
 data: one each for the Google, Infoseek,
and Lycos search engines. The applet then uses 
showDocument
 to instruct
the browser to display the results of those URLs in three different frame
cells. The results are shown in Figures 17 1 and 17 2. HTML forms cannot
be used for this application since a form can submit its data to only a single
URL.
Listing 17.2 shows the top level HTML document used and Listing 17.3
shows the HTML used for the frame cell actually containing the applet.
Please refer to this book's Web site (
http://www.coreservlets.com/
) for
the three tiny HTML files used for the initial contents of the bottom three
frame cells shown in Figure 17 1. 
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




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

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