Slim3 Controller‎ > ‎

Request, Response and ServletContext

HttpServletRequest, HttpServletResponse and ServletContext are located on Controller. You can also reference them via RequestLocator.get(), ResponseLocator.get() and ServletContextLocator.get() as follows:
HttpServletRequest request = RequestLocator.get();
HttpServletResponse response = ResponseLocator.get();
ServletContext servletContext = ServletContextLocator.get();

The parameters of request are copied to the attributes of request by RequestHandler because of convenient access via view like JSP.
Note: The parameter whose name ends with "Array" is copied as an array of strings.

Controller has a lot of convenient methods to access the attributes of request like asString(), asShort(), asInteger(), asLong(), asFloat(), asDouble(), asBoolean(), asDate() and asKey():
// the argument is a attribute name
Key key = asKey("key");
Long version = asLong("version");

If the attribute is stored to a model, you can specify it type-safely using Meta data of model:
XxxMeta meta = XxxMeta().get();
Key key = asKey(meta.key);
Long version = asLong(meta.version);

You can copy the attributes of request to a model using BeanUtil#copy() as follows:
Blog blog = new Blog();
BeanUtil.copy(request, blog);


Continue to File Upload.