javawebparts.servlet
Class TextReturnerServlet
java.lang.Object
|
+--javax.servlet.GenericServlet
|
+--javax.servlet.http.HttpServlet
|
+--javawebparts.servlet.TextReturnerServlet
- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- public class TextReturnerServlet
- extends javax.servlet.http.HttpServlet
This servlet returns a string from an XML 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.
Example configuration in web.xml:
<servlet>
<servlet-name>TextReturnerServlet</servlet-name>
<servlet-class>javawebparts.servlet.
TextReturnerServlet</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/text_returner_items.xml
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>TextReturnerServlet</servlet-name>
<url-pattern>/textReturner</url-pattern>
</servlet-mapping>
Example items configuration file:
<TextReturnerServletItems>
<item>0 - It's always darkest before the dawn</item>
<item>1 - A journey of a thousand miles begins with a
single step</item>
<item>2 - The universe is like stupidity: both are
infinite... and actually, I'm not sure about the universe</item>
<item>3 - I believe there is intelligent life in the
universe, except for some parts of New Jersey</item>
<item>4 - If your falling of a cliff, you might as well
try and fly</item>
<item>5 - The cost of life is to chance the consequence
</item>
</TextReturnerServletItems>
- 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 |
|
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 |
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.
TextReturnerServlet
public TextReturnerServlet()
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
- HTTPServletRequestresponse
- HTTPServletResponse
- Throws:
javax.servlet.ServletException
- ServletException
java.io.IOException
- IOException
Copyright © 2005 Frank W. Zammetti