Overview | Package | Class | Deprecated | Index | Help
| Groovy 1.7.10
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.servlet
[Java] Class ServletBinding

    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.

### Eager variables

- `"request"` : the HttpServletRequest object
- `"response"` : the HttpServletRequest object
- `"context"` : the ServletContext object
- `"application"` : same as context
- `"session"` : shorthand for `request.getSession(`false`)` - can be null!
- `"params"` : map of all form parameters - can be empty
- `"headers"` : map of all `request` header fields

### Lazy variables

- `"out"` : response.getWriter()
- `"sout"` : response.getOutputStream()
- `"html"` : new MarkupBuilder(response.getWriter())

As per specification a call to response.getWriter() should not be done if a call to response.getOutputStream() have been done already and the other way around. Lazy bound variables can be requested without side effects, since the writer and stream is wrapped. That means response.getWriter() is not directly called if 'out' or 'html' is requested. Only if a write method call is done using the variable, a write method call on 'sout' will cause a IllegalStateException. If a write method call on 'sout' has been done already any further write method call on 'out' or 'html' will cause a IllegalStateException.

If 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.getOoutputStream() and using 'out' or 'html'.

### Methods

- `"forward(String path)"` : request.getRequestDispatcher(path).forward(request, response);
- `"include(String path)"` : request.getRequestDispatcher(path).include(request, response);
- `"redirect(String location)"` : response.sendRedirect(location);

Authors:
  Guillaume Laforge
  Christian Stein
  Jochen Theodorou

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, 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

### ServletBinding

    public def ServletBinding(HttpServletRequest request, HttpServletResponse response, ServletContext context)

  Initializes a servlet binding.
  Parameters:
    `request` - the HttpServletRequest object
    `response` - the HttpServletRequest object
    `context` - the ServletContext object

### forward

    public void forward(String path)

### getVariable

    @Override
    public Object getVariable(String name)

  Returns:
    a writer, an output stream, a markup builder or another requested object

### getVariables

    @Override
    public Map getVariables()

### include

    public void include(String path)

### redirect

    public void redirect(String location)

### setVariable

    @Override
    public void setVariable(String name, Object value)

Copyright © 2003-2010 The Codehaus. All rights reserved.