javawebparts.servlet
Class RedirectReturnerServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--javawebparts.servlet.RedirectReturnerServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class RedirectReturnerServlet
extends javax.servlet.http.HttpServlet

This servlet returns a URL as defined in an XML file. It builds a collection of URIs from the config file. Each invocation of the servlet returns one of the items, either randomly (with no repeats) until all items have been shown) or in forward or reverse order. The URIs in the config file can be a complete URL (i.e., beginning with http://, https://, ftp://, etc.) or can be context-relative (i.e., beginning with a /).

Example configuration in web.xml:

<servlet>
  <servlet-name>RedirectReturnerServlet</servlet-name>
  <servlet-class>javawebparts.servlet. RedirectReturnerServlet</servlet-class>
  <init-param>
    <param-name>order</param-name>
    <param-value>random</param-value>
  </init-param>
  <init-param>
    <param-name>itemsFile</param-name>
    <param-value> /WEB-INF/redirect_returner_items.xml</param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>RedirectReturnerServlet</servlet-name>
  <url-pattern>/redirectReturner</url-pattern>
</servlet-mapping>

Example items configuration file:

<RedirectReturnerServletItems>
  <item>http://www.google.com/intl/en/images/logo.gif </item>
  <item>/img/header1.gif</item>
  <item>/img/mouse.gif</item>
  <item>http://javawebparts.sourceforge.net/logo.jpg </item>
</RedirectReturnerServletItems>

Author:
Frank W. Zammetti.
See Also:
Serialized Form

Field Summary
private  Items items
          Bean that holds all our items from the file, and generally does all the work of this servlet.
private static org.apache.commons.logging.Log log
          Log instance.
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Fields inherited from class javax.servlet.GenericServlet
 
Constructor Summary
RedirectReturnerServlet()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          doGet.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          doPost.
 void init(javax.servlet.ServletConfig config)
          init.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.


items

private Items items
Bean that holds all our items from the file, and generally does all the work of this servlet.

Constructor Detail

RedirectReturnerServlet

public RedirectReturnerServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
init.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - ServletConfig.
Throws:
javax.servlet.ServletException - ServletException.

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  java.io.IOException
doGet. Calls doPost() to do real work.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - HTTPServletRequest.
response - HTTPServletResponse.
Throws:
javax.servlet.ServletException - ServletException.
java.io.IOException - IOException.

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   java.io.IOException
doPost.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - HTTPServletRequest
response - HTTPServletResponse
Throws:
javax.servlet.ServletException - ServletException
java.io.IOException - IOException


Copyright © 2005 Frank W. Zammetti