Java
  Home arrow Java arrow Creating a User Interface for a Search Ser...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Creating a User Interface for a Search Service
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-11-22

    Table of Contents:
  • Creating a User Interface for a Search Service
  • Changes to the Original Code to Fit the JSP
  • Setting Up the Indexer
  • Making Use of the Configuration Service

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a User Interface for a Search Service


    (Page 1 of 4 )

    Last week, we started building a search service for a website. This week, we're going to cover the user interface and the indexer. This article is excerpted from chapter 10 of the book Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764).

    The User Interface (JSP)

    The user interface is fairly straightforward. Instead of just dumping our results to the console or creating an XML document of the results (as in the web service implementation from Chapter 9), this time we need to write a JSP that iterates over the results and displays them as hyperlinks in a table.

    The originaljPetStore search feature used aPagedListHolderfor its results because it displayed the image associated with each returned product in the table. Since the images were arbitrary in size,jPetStoredidn’t want to display too many entries on a given page since it might result in a lot of vertical scrolling. Our results consist of a hyperlink to the returned URL and the relative rank of the given result; therefore, we’ll use a simple table to display our results.

    Again, we are faced with the rewrite-or-replace question. Just like last time, we have three questions to consider:

    1. Do we have access to the original source? We must, since JSPs are just text files in both development and deployment mode.
    2. Will we ever want to reuse the existing service? We do, but in this case, a JSP is so easy to recreate that it won’t make much difference.
    3. Does the current version implement some standard interface? Not as such, since JSPs are just mixes of static HTML and dynamic content.

    Because of the rather trivial nature of the changes and because JSPs are easily edited in place (no compilation necessary), we’ll just repurpose the existing SearchProducts.jsp file. This strategy saves us from having to change any more configuration settings:

      <%@ include file="IncludeTop.jsp" %>

      <table align="left" bgcolor="#008800" border="0" cellspacing="2" cellpadding="2">
      <tr> 
       
    <td bgcolor="#FFFF88">
       
    <a href="<c:url value="/shop/index.do"/>">
          
    <b><font color="BLACK" size="2"> &lt;&lt; Main Menu</font></b>
        
    </a>
        </td>
     
    </tr>
      </table>
      <table align="center" bgcolor="#008800" border="0" cellspacing="2"
         
    cellpadding="3">

          <tr bgcolor="#CCCCCC"> <td><b>URL</b></td> <td><b>Rank</b></td> </tr>
          <c:forEach var="page" items="${hits}">
                
    <tr bgcolor="#FFFF88">
                
    <td><a href="<c:out value="${page.url}"/>">
                     
    <c:out value="${page.url}"/></a>
                
    </td>
               
    <td>
                   
    <c:out value="${page.score}"/>
              </td>
                </tr>
          </c:forEach>
      </table>

      <%@ include file="IncludeBottom.jsp" %>

    The JSP files in the application have a standard header and footer defined in IncludeTop.jsp and IncludeBottom.jsp. All we have to do is render the results in between the include directives. Start by creating a JSP-styleforEachloop, with an enumerator calledpagepointing at each member of theHashMapcalled “hits.” For each hit, we render a table row containing the URL (the value of which is both the text to display and the HREF to point it to) and the relative rank of the hit. JSP handles hooking up the variables and properties using reflection. However, when implementing this page, we come across the first (and only) reason to change some of the original Spider code.

    More Java Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Better, Faster, Lighter Java," published...
     

    Buy this book now. This article is excerpted from chapter 10 of the book Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT