public class ServletBinding extends Binding
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)
Constructor and Description |
---|
ServletBinding(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.ServletContext context)
Initializes a servlet binding.
|
Modifier and Type | Method and Description |
---|---|
void |
forward(java.lang.String path) |
java.lang.Object |
getVariable(java.lang.String name) |
java.util.Map |
getVariables() |
void |
include(java.lang.String path) |
void |
redirect(java.lang.String location) |
void |
setVariable(java.lang.String name,
java.lang.Object value)
Sets the value of the given variable
|
getProperty, hasVariable, setProperty
getMetaClass, invokeMethod, setMetaClass
public ServletBinding(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext context)
request
- the HttpServletRequest objectresponse
- the HttpServletRequest objectcontext
- the ServletContext objectpublic void setVariable(java.lang.String name, java.lang.Object value)
Binding
setVariable
in class Binding
name
- the name of the variable to setvalue
- the new value for the given variablepublic java.util.Map getVariables()
getVariables
in class Binding
public java.lang.Object getVariable(java.lang.String name)
getVariable
in class Binding
name
- the name of the variable to lookuppublic void forward(java.lang.String path) throws javax.servlet.ServletException, java.io.IOException
javax.servlet.ServletException
java.io.IOException
public void include(java.lang.String path) throws javax.servlet.ServletException, java.io.IOException
javax.servlet.ServletException
java.io.IOException
public void redirect(java.lang.String location) throws java.io.IOException
java.io.IOException