|
Groovy 2.2.0 | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovy.lang.GroovyObjectSupport groovy.lang.Binding groovy.servlet.ServletBinding
public class ServletBinding extends Binding
Servlet-specific binding extension to lazy load the writer or the output stream from the response.
HttpServletRequest
objectHttpServletRequest
objectServletContext
objectrequest.getSession(false)
- can be null!
response.getWriter()
response.getOutputStream()
new MarkupBuilder(response.getWriter())
- expandEmptyElements
flag is set to truenew JsonBuilder()
response.getWriter()
should not be
done if a call to response.getOutputStream()
has already occurred or the other way
around. You may wonder then how the above lazy variables can possibly be provided - since
setting them up would involve calling both of the above methods. The trick is catered for
behind the scenes using lazy variables. Lazy bound variables can be requested without side
effects; under the covers the writer and stream are wrapped. That means
response.getWriter()
is never directly called until some output is done using
'out' or 'html'. Once a write method call is done using either of these variable, then an attempt
to write using 'sout' will cause an IllegalStateException
. Similarly, if a write method
call on 'sout' has been done already, then any further write method call on 'out' or 'html' will cause an
IllegalStateException
.
response.getWriter()
is called directly (without using out), then a write method
call on 'sout' will not cause the IllegalStateException
, but it will still be invalid.
It is the responsibility of the user of this class, to not to mix these different usage
styles. The same applies to calling response.getOutputStream()
and using 'out' or 'html'.
request.getRequestDispatcher(path).forward(request, response)
request.getRequestDispatcher(path).include(request, response)
response.sendRedirect(location)
Method Summary | |
---|---|
def
|
ServletBinding(HttpServletRequest request, HttpServletResponse response, ServletContext context)
Initializes a servlet binding. |
void
|
forward(String path)
|
Object
|
getVariable(String name)
@return a writer, an output stream, a markup builder or another requested object |
Map
|
getVariables()
|
void
|
include(String path)
|
void
|
redirect(String location)
|
void
|
setVariable(String name, Object value)
|
Methods inherited from class Binding | |
---|---|
getProperty, getVariable, getVariables, hasVariable, setProperty, setVariable |
Methods inherited from class GroovyObjectSupport | |
---|---|
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Method Detail |
---|
public def ServletBinding(HttpServletRequest request, HttpServletResponse response, ServletContext context)
request
- the HttpServletRequest objectresponse
- the HttpServletRequest objectcontext
- the ServletContext object
public void forward(String path)
@Override public Object getVariable(String name)
@Override public Map getVariables()
public void include(String path)
public void redirect(String location)
@Override public void setVariable(String name, Object value)
Copyright © 2003-2013 The Codehaus. All rights reserved.