Servlet, allows you to search files on your web server. How to use it: 1) download searchPackage.jar and save it in WEB-INF/lib 2) describe Search servlet in web.xml file
<servlet> <servlet-name>Search</servlet-name> <servlet-class>com.cj.search.SearchServlet</servlet-class> </servlet> 3) define a mapping:
<servlet-mapping> <servlet-name>Search</servlet-name> <url-pattern>/servlet/Search</url-pattern> </servlet-mapping> Now you can set this servlet (in our example it is /servlet/Search) as an action parameter for your html form. Also you have to provide a configuration file (as an initial parameter or as a GET parameter). This file describes various environment settings for your search. You can pass parameter in query string or define it as an initial parameter for this servlet. Direct setting of configuration file The usage is:
/servlet/Search?config_file E.g. some like that:
or in html-tags:
<html> <form action="http://your_host/servlet/Search?c:\files\my_config.txt" method="post"> <input type="Text" name="search"> <input type="Submit" value="Search"> </form> </html> Servlet supports WAP/WML, so you may use the same tool for your WAP sites:
<wml> <card id="searchcard" title="Search"> <do type="accept" label="Search"> <go href="http://your_host/servlet/Search?your_config_file" method="post"> <postfield name="search" value="$(sSearch)"/> </go> </do> <p>Query: <input name="sSearch" value="" emptyok="false"/></p> </card> </wml> Configuration file as an initial parameter You may set configuration file as a parameter for this servlet. Parameter name
is conf. E.g. you may have some like this in your web.xml file
<servlet> <servlet-name>Search</servlet-name> <servlet-class>com.cj.search.SearchServlet</servlet-class> <init-param> <param-name>conf</param-name> <param-value>path_to_your_configuration_file</param-value> </init-param> </servlet> and now you do not need to pass config file in your query:
<html> <form action="http://your_host/servlet/Search" method="post"> <input type="Text" name="search"> <input type="Submit" value="Search"> </form> </html> So servlet will obtain a query string from HTML (WML) form and proceed a search. Files for search will be described in the configuration file. Output could be generated through this servlet itself (you will be able to configure look and feel) or through your own JSP page. Configuration file Configuration file is a text file describes servlet's settings. You can save this file anywhere on your server. This is a text file, each line describes one parameter in the form of parameter=value Empty lines and any line starts with # or // are ignored. Current version supports the following list of parameters: # root directory for the search. By default it is a . (root directory
of your servletrunner)
# excluded directories. You may exclude some subdirectories from search
# web. URL for your root directory
# forward. Optional parameter. Describes your own JSP page for reports
# ext. Comma separated list of file extensions for files being searched.
By default it is
# HTML/XML tags policy. You may skip tags during your search
# Field name for the search query. By default it is search
# Background color for the result page. By default it is #FFFFFF (white).
# Foreground color for the result page. By default it is #000000 (black).
# font face. By default it is a current browser's font.
# font size. By default it is a current browser's font.
# page size (documents per page). By default it is 30
# how many pages are visible on the bottom. By default
# title. Default value is Coldbeans search
# header. You can set any HTML code for output on the top for each page.
# footer. You can set any HTML code for output on the bottom for each page.
# temp directory. This directory will be used for
# open. How to open founded documents.
# javascript settings for new window (in case of open=1). E.g.:
# You can set also your own page for "found no documents" output.
# localization support. You can set character encoding for input parameters
# charset for output. Default value is ISO-8859-1
# customization. You may define here your own templates
# template for counter
# template for founded elements
# template for pages string
Examples In general you have to provide a directory for searched files and a URI, describes a web access to this directory. For example (it is for Orion server in the default configuration): root=c:\orion\default-web-app
here servlet will search files in c:\orion\default-web-app and discovered items will be visible as http://your_host:8080/file_name. In other words parameter root describes a real location for searched files and parameter web describes an URI for this directory. As soon as you set a parameter forward the output will passed to your own JSP page. You can use Search taglib for creating your own reports. Otherwise the same servlet will create a report with your results. And that report could be configured through templates. Search tips: Search servlet defines a word as any combination of letters and
numbers that is separated by any of the following:
A search phrase is a group of words or numbers linked together. Use lowercase text in your searches. When you use lowercase text, the search service finds both uppercase and lowercase results. When you use uppercase text, the search service only finds uppercase results. To make sure that a word is always included in your search, place a plus sign (+) immediately before the keyword (no spaces) in the search box. To make sure that a word is always excluded from your search, place a minus sign (-) immediately before the keyword (no spaces) in the search box. Templates You may describe your patterns for elements in output. There are 3 templates.
First one describes what will be outputted as a common search result. By default
servlet will print some like this 10 document found. You may set in config
your own content for this output. E.g.:
template1=c:\search\myheader.txt Found $N documents Meta-symbol $N will be replaced with the actual number before output Next template defines pattern for founded elements. You may use meta-symbols:
$N - sequential number
For example, default template could be described so:
<br>$N. <a href="$U">$T</a> <br>URL:$U <br>Last modified on: $T Size: $S And the latest template (template3) defines pattern for list of pages (by default servlet prints Pages:). So templates let you to completely redesign output or localize it for example. Notes: 1. Configuration file can be saved anywhere on your server. E.g. if you are using /servlet/Search?config call we assume this file is saved under the root directory of servletrunner. But you can of course always use the full name for setting config file location: /servlet/Search?/home/users/my_file (or /servlet/Search?c:\users\my_file) or a full path relatively to the web root: /servlet/Search?/data/conf.txt 2. Evaluation version displays the first 3 pages only.
for downloading: Search package: searchPackage.jar sample of configuration file: findconf See also JSOS - the largest collection of servlets and filters.
|
Also in JSOS:
|