Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
8.6 A Customized Search Engine Interface
191
Listing 8.3 ServletUtilities.java 
package coreservlets;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletUtilities {
// Other methods in this class shown in earlier chapters.
  public static String getCookieValue(Cookie[] cookies,
                                      String cookieName,
                                      String defaultValue) {
    for(int i=0; i
      Cookie cookie = cookies[i];
      if (cookieName.equals(cookie.getName()))
        return(cookie.getValue());
    }
    return(defaultValue);
  }
  public static Cookie getCookie(Cookie[] cookies,
                                 String cookieName) {
    for(int i=0; i
      Cookie cookie = cookies[i];
      if (cookieName.equals(cookie.getName()))
        return(cookie);
    }
    return(null);
  }
}
Creating Long Lived Cookies
Listing 8.4 shows a small class that you can use instead of 
Cookie
 if you want
your cookie to automatically persist when the client quits the browser. See
Listing 8.5 for a servlet that uses this class. 
8.6 A Customized Search Engine 
Interface
Listing 8.5 shows the 
CustomizedSearchEngines
 servlet, a variation of the
SearchEngines
 example previously shown in Section 6.3. Like the 
Search 
Engines
 servlet (see Figure 8 5), the 
CustomizedSearchEngines
 servlet
Second edition of this book: www.coreservlets.com; 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