MDi JLib
1.7.4

com.microdeveloper.servlets.io
Class PostRedirect

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.microdeveloper.servlets.io.PostRedirect
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class PostRedirect
extends HttpServlet

PostRedirect will accept a request and redirect it as a post type request to another destination URL allowing the instantiated servlet to override certain parameters from the original post.

An example of usage would be to invoke a report, passing parameters such as order number, but letting a custom method determine the exact report to run for the given request or user. Another usage would be to validate or remove unwanted or unsafe parameters before invoking the target.

Finally, by using the redirection, the actual target is not visible in the URL.

Since:
1.7
Version:
1.0
Author:
Gregg Lagnese
See Also:
Serialized Form

Constructor Summary
PostRedirect()
           
 
Method Summary
 void destroy()
          Destroys the servlet.
protected  void doGet(HttpServletRequest request, HttpServletResponse response)
          Handles the HTTP GET method.
protected  void doPost(HttpServletRequest request, HttpServletResponse response)
          Handles the HTTP POST method.
 String getServletInfo()
          Returns a short description of the servlet.
 void init(ServletConfig config)
          Initializes the servlet.
protected  void processRequest(HttpServletRequest request, HttpServletResponse response)
          Processes requests for both HTTP GET and POST methods.
 void sendRedirect(HttpServletRequest request, HttpServletResponse response)
          Process the redirection to the destination.
protected  Hashtable setOverrideParams(Hashtable params)
          Overrides and potentially replaces original request parameters
protected  void setServletProperties(String paramFile)
          The servlet properties which defines the default protocol (scheme), server, port, and path.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostRedirect

public PostRedirect()
Method Detail

getServletInfo

public String getServletInfo()
Returns a short description of the servlet.

Specified by:
getServletInfo in interface Servlet
Overrides:
getServletInfo in class GenericServlet
Returns:
Short description

destroy

public void destroy()
Destroys the servlet.

Specified by:
destroy in interface Servlet
Overrides:
destroy in class GenericServlet

init

public void init(ServletConfig config)
          throws ServletException
Initializes the servlet.

Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Parameters:
config - Configuration for the servlet
Throws:
ServletException - Standard servlet exception

sendRedirect

public void sendRedirect(HttpServletRequest request,
                         HttpServletResponse response)
                  throws ServletException,
                         IOException

Process the redirection to the destination. Uses customUrl to allow the overriding of the fetched parameters so they can be pre-processed by custom routines. This is not required however and the default method does nothing to the parameters unless overridden.

Parameters:
request - servlet request
response - servlet response
Throws:
ServletException - standard servlet exception
IOException - standard io exception

doGet

protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
              throws ServletException,
                     IOException
Handles the HTTP GET method.

Overrides:
doGet in class HttpServlet
Parameters:
request - servlet request
response - servlet response
Throws:
ServletException - standard servlet exception
IOException - standard io exception

doPost

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response)
               throws ServletException,
                      IOException
Handles the HTTP POST method.

Overrides:
doPost in class HttpServlet
Parameters:
request - servlet request
response - servlet response
Throws:
ServletException - standard servlet exception
IOException - standard io exception

processRequest

protected void processRequest(HttpServletRequest request,
                              HttpServletResponse response)
                       throws ServletException,
                              IOException
Processes requests for both HTTP GET and POST methods.

Parameters:
request - servlet request
response - servlet response
Throws:
ServletException - standard servlet exception
IOException - standard io exception

setServletProperties

protected void setServletProperties(String paramFile)
                             throws ServletException,
                                    IOException

The servlet properties which defines the default protocol (scheme), server, port, and path. Only the default server must be set in the properties file. If this is not present, the servlet will not initialize. The default url would be HTTP://[server]:80

This method can be overriden to add additional properties, such as default database credentials, but must always include the following:

These elements must be present even if they are absent from the actual parameter file itself.

You can also use the setOverrideParams method to introduce custom parameters instead of overriding this method. Just fetch additional parameters there and add them to the post variables (for logon credentials for example)

Parameters:
paramFile - full path to the parameter file
Throws:
ServletException - standard servlet exception
IOException - standard io exception

setOverrideParams

protected Hashtable setOverrideParams(Hashtable params)
Overrides and potentially replaces original request parameters

Parameters:
params - Original request parameter Hashtable
Returns:
Final parameters as a Hashtable

MDi JLib
1.7.4

Copyright©2001-2007 MicroDeveloper, Inc. All Rights Reserved.