org.codehaus.groovy.grails.web.pages
Class GroovyPagesServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.codehaus.groovy.grails.web.pages.GroovyPagesServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class GroovyPagesServlet
extends HttpServlet

NOTE: Based on work done by on the GSP standalone project (https://gsp.dev.java.net/) Main servlet class. Example usage in web.xml: GroovyPagesServlet org.codehaus.groovy.grails.web.pages.GroovyPagesServlet showSource 1 Allows developers to view the intermediade source code, when they pass a showSource argument in the URL (eg /edit/list?showSource=true.

Author:
Troy Heninger, Graeme Rocher Date: Jan 10, 2004
See Also:
Serialized Form

Field Summary
static String EXCEPTION_MODEL_KEY
           
static String SERVLET_INSTANCE
           
 
Constructor Summary
GroovyPagesServlet()
           
 
Method Summary
protected  Writer createResponseWriter(HttpServletResponse response)
          Creates a response writer for the given response object
 void doGet(HttpServletRequest request, HttpServletResponse response)
           
 void doPage(HttpServletRequest request, HttpServletResponse response)
          Execute page and produce output.
 void doPost(HttpServletRequest request, HttpServletResponse response)
           
 ServletContext getServletContext()
           
protected  void handleException(Exception exception, Writer out, GroovyPagesTemplateEngine engine)
          Performs exception handling by attempting to render the Errors view
 void init(ServletConfig config)
          Initialize the servlet, set it's parameters.
protected  void renderPageWithEngine(GroovyPagesTemplateEngine engine, HttpServletRequest request, HttpServletResponse response, Resource pageResource)
          Attempts to render the page with the given arguments
 
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, 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

EXCEPTION_MODEL_KEY

public static final String EXCEPTION_MODEL_KEY
See Also:
Constant Field Values

SERVLET_INSTANCE

public static final String SERVLET_INSTANCE
See Also:
Constant Field Values
Constructor Detail

GroovyPagesServlet

public GroovyPagesServlet()
Method Detail

init

public void init(ServletConfig config)
Initialize the servlet, set it's parameters.

Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Parameters:
config - servlet settings

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws ServletException,
                  IOException
Overrides:
doGet in class HttpServlet
Throws:
ServletException
IOException

doPost

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
            throws ServletException,
                   IOException
Overrides:
doPost in class HttpServlet
Throws:
ServletException
IOException

getServletContext

public ServletContext getServletContext()
Specified by:
getServletContext in interface ServletConfig
Overrides:
getServletContext in class GenericServlet
Returns:
the servlet context

doPage

public void doPage(HttpServletRequest request,
                   HttpServletResponse response)
            throws ServletException,
                   IOException
Execute page and produce output.

Parameters:
request - The HttpServletRequest insance
response - The HttpServletResponse instance
Throws:
ServletException - Thrown when an exception occurs executing the servlet
IOException - Thrown when an IOException occurs executing the servlet

renderPageWithEngine

protected void renderPageWithEngine(GroovyPagesTemplateEngine engine,
                                    HttpServletRequest request,
                                    HttpServletResponse response,
                                    Resource pageResource)
                             throws IOException,
                                    ServletException
Attempts to render the page with the given arguments

Parameters:
engine - The GroovyPagesTemplateEngine to use
request - The HttpServletRequest
response - The HttpServletResponse
pageResource - The URL of the page
Throws:
IOException - Thrown when an I/O exception occurs rendering the page
ServletException - Thrown when an exception occurs in the servlet environment

handleException

protected void handleException(Exception exception,
                               Writer out,
                               GroovyPagesTemplateEngine engine)
                        throws ServletException,
                               IOException
Performs exception handling by attempting to render the Errors view

Parameters:
exception - The exception that occured
out - The Writer
engine - The GSP engine
Throws:
IOException - Thrown when an I/O exception occurs rendering the page
ServletException - Thrown when an exception occurs in the servlet environment

createResponseWriter

protected Writer createResponseWriter(HttpServletResponse response)
Creates a response writer for the given response object

Parameters:
response - The HttpServletResponse
Returns:
The created java.io.Writer


Copyright (c) 2005-2009 The Grails project