Expresso 5-6

com.jcorporate.expresso.core.servlet
Class StdServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bycom.jcorporate.expresso.core.servlet.StdServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
DBServlet

public abstract class StdServlet
extends HttpServlet

A Servlet base class adding some basic common functionality to the core HttpServlet class.

Author:
Michael Nash
See Also:
DBServlet, Serialized Form

Field Summary
protected  String mySchema
           
protected static String thisClass
           
 
Constructor Summary
StdServlet()
           
 
Method Summary
 void destroy()
          Called when the web context is destroyed or reloaded
 void doGet(HttpServletRequest request, HttpServletResponse response)
          Ancestor calls this function (with super.doGet) to handle making database connection, getting user login info and other common tasks.
 void doPost(HttpServletRequest req, HttpServletResponse res)
          Ancestor calls this method via super.doPost to handle standard operations.
protected  String getSchema()
          Return the name of the schema class that this servlet is registered within
protected  String getServerName(HttpServletRequest request)
          Return the name of the current web server system
 int getServerPort(HttpServletRequest request)
          Return the port number the servlet runtime engine is running on
 String getServletPrefix(HttpServletRequest request)
          Return a string to be used as part of the URL to call this servlet.
 String getServletPrefix(HttpServletRequest request, String servlet)
           
 String getString(HttpServletRequest req, String stringCode)
          Convenience method to request a localized message with no parameters
 String getString(HttpServletRequest req, String stringCode, Object[] args)
          Pass on a call to retrieve an appropriate localized string from the correct Schema object
 String getTitle()
          Ancestors of this class override this method to return a specific title that is used by the security administration Controllers to describe the servlet
protected  void handleParam(HttpServletRequest request, HttpServletResponse response)
          Handle the parameters to this servlet & set up standard information
 void init(ServletConfig sc)
          Servlet initialization.
protected  void setSchema(String schemaClass)
          Tell this StdServlet object what Schema it belongs to.
protected  void showError(String errorMessage, HttpServletRequest request, HttpServletResponse response)
          Display an error to the user in a nicely formatted manner
protected  void showError(Throwable t, HttpServletRequest request, HttpServletResponse response)
          Display a throwable (like an exception) to the user in a nicely formatted manner.
 
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, 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

thisClass

protected static final String thisClass

mySchema

protected String mySchema
Constructor Detail

StdServlet

public StdServlet()
Method Detail

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws ServletException,
                  IOException
Ancestor calls this function (with super.doGet) to handle making database connection, getting user login info and other common tasks.

Parameters:
request - Standard request object
response - Standard response object
Throws:
ServletException - If an uncaught exception occurs
IOException - If an I/O error occurs while communicating with the client

doPost

public void doPost(HttpServletRequest req,
                   HttpServletResponse res)
            throws ServletException,
                   IOException
Ancestor calls this method via super.doPost to handle standard operations.

Parameters:
req - Standard request object
res - Standard response object
Throws:
ServletException - If an uncaught exception occurs
IOException - If an I/O error occurs while communicating with the client

getServerName

protected String getServerName(HttpServletRequest request)
Return the name of the current web server system

Parameters:
request -
Returns:
String The name of the current web server

getServerPort

public int getServerPort(HttpServletRequest request)
Return the port number the servlet runtime engine is running on

Parameters:
request -
Returns:
int The port number for servlets

getServletPrefix

public String getServletPrefix(HttpServletRequest request)
                        throws ServletException
Return a string to be used as part of the URL to call this servlet. Often used by doGet methods to build the action for a form to call the doPost method of the same servlet.

Parameters:
request -
Returns:
String The string for building a URL
Throws:
ServletException - If the string cannot be built due to setup information not being available

getServletPrefix

public String getServletPrefix(HttpServletRequest request,
                               String servlet)
                        throws ServletException
Parameters:
request -
servlet -
Returns:
Throws:
ServletException

getTitle

public String getTitle()
Ancestors of this class override this method to return a specific title that is used by the security administration Controllers to describe the servlet

Returns:

handleParam

protected void handleParam(HttpServletRequest request,
                           HttpServletResponse response)
                    throws IOException,
                           ServletException
Handle the parameters to this servlet & set up standard information

Parameters:
request - Standard request object
response - Standard response object
Throws:
IOException - If an I/O error occurs communicating with the client
ServletException - If an uncaught exception occurs

showError

protected void showError(String errorMessage,
                         HttpServletRequest request,
                         HttpServletResponse response)
                  throws ServletException
Display an error to the user in a nicely formatted manner

Parameters:
errorMessage - Error message
request -
response -
Throws:
ServletException

showError

protected void showError(Throwable t,
                         HttpServletRequest request,
                         HttpServletResponse response)
                  throws ServletException
Display a throwable (like an exception) to the user in a nicely formatted manner. Also show the stack trace in an HTML comment

Parameters:
t - The throwable error
request -
response -
Throws:
ServletException

init

public void init(ServletConfig sc)
          throws ServletException
Servlet initialization. Checks to make sure ConfigManager has been initialized and starts the configuration process if it hasn't.

Parameters:
sc - The ServletConfig. Should contain 'configDir' as a context parameter, and possibly 'logDir'.
Throws:
ServletException

destroy

public void destroy()
Called when the web context is destroyed or reloaded


setSchema

protected void setSchema(String schemaClass)
Tell this StdServlet object what Schema it belongs to. This is used when the Controller tries to use it's "getString(String, Object[])" method to prepare internationalized messages - it passes the call along to the appropriate schema which knows how to locate the proper message file

Parameters:
schemaClass -

getString

public String getString(HttpServletRequest req,
                        String stringCode,
                        Object[] args)
                 throws ServletException
Pass on a call to retrieve an appropriate localized string from the correct Schema object

Parameters:
req -
stringCode -
args -
Returns:
Throws:
ServletException

getString

public String getString(HttpServletRequest req,
                        String stringCode)
                 throws ServletException
Convenience method to request a localized message with no parameters

Parameters:
req -
stringCode -
Returns:
Throws:
ServletException

getSchema

protected String getSchema()
Return the name of the schema class that this servlet is registered within

Returns:

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.