public final class RequestContext extends Object
| Constructor and Description |
|---|
RequestContext() |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Aborts the remaining handlers.
|
void |
addHandler(Handler handler)
Adds the specified handler to handler chain.
|
void |
addHeader(String name,
String value)
Adds a header specified by the given name and value to the response.
|
Object |
attr(String name)
Gets an attribute specified by the given name from request.
|
void |
attr(String name,
Object value)
Sets an attribute specified by the given name and value into request.
|
Map<String,Object> |
getDataModel()
Gets the data model of renderer bound with this context.
|
AbstractResponseRenderer |
getRenderer()
Gets the renderer.
|
Request |
getRequest()
Gets the request.
|
Response |
getResponse()
Gets the response.
|
void |
handle()
Handles this context with handlers.
|
String |
header(String name)
Gets the value of a header specified by the given name
|
String |
method()
Gets the request HTTP method.
|
String |
param(String name)
Gets a parameter specified by the given name from request body form or query string.
|
String |
pathVar(String name)
Gets a path var specified by the given name from request URI.
|
void |
pathVar(String name,
String value)
Puts a path var specified by the given name and value.
|
Map<String,String> |
pathVars()
Get all path vars.
|
void |
pathVars(Map<String,String> pathVars)
Set all path vars.
|
String |
remoteAddr()
Gets the remote address of request.
|
RequestContext |
renderCode(int code)
Renders with {"code": int}.
|
RequestContext |
renderData(Object data)
Renders with {"data": obj}.
|
RequestContext |
renderFalseResult()
Renders with {"sc": false}.
|
RequestContext |
renderJSON()
Renders using
JsonRenderer with {"sc": false}. |
RequestContext |
renderJSON(boolean sc)
Renders using
JsonRenderer with {"sc": sc}. |
RequestContext |
renderJSON(int code)
Renders using
JsonRenderer with {"code": int}. |
RequestContext |
renderJSON(JSONObject json)
Renders with the specified json object.
|
RequestContext |
renderJSONPretty(JSONObject json)
Pretty rends with the specified json object.
|
RequestContext |
renderJSONValue(String name,
Object obj)
Renders with {"name", obj}.
|
RequestContext |
renderMsg(String msg)
Renders with {"msg": msg}.
|
RequestContext |
renderPretty()
Pretty renders.
|
RequestContext |
renderTrueResult()
Renders with {"sc": true}.
|
JSONObject |
requestJSON()
Gets the request json object.
|
String |
requestURI()
Gets the request URI.
|
void |
sendError(int sc)
Sends the specified error status code.
|
void |
sendRedirect(String location)
Sends redirect to the specified location.
|
void |
sendStatus(int sc)
Sends the specified status code.
|
void |
setHeader(String name,
String value)
Sets a header specified by the given name and value to the response.
|
void |
setRenderer(AbstractResponseRenderer renderer)
Sets the renderer with the specified renderer.
|
void |
setRequest(Request request)
Sets the request with the specified request.
|
void |
setResponse(Response response)
Sets the response with the specified response.
|
void |
setStatus(int sc)
Sends the specified status code.
|
public AbstractResponseRenderer getRenderer()
public void setRenderer(AbstractResponseRenderer renderer)
renderer - the specified rendererpublic Request getRequest()
public void setRequest(Request request)
request - the specified requestpublic Response getResponse()
public void setResponse(Response response)
response - the specified responsepublic Map<String,Object> getDataModel()
null if not foundpublic String remoteAddr()
public void sendRedirect(String location)
location - the specified locationpublic String header(String name)
name - the given namepublic void addHeader(String name, String value)
name - the given namevalue - the given valuepublic void setHeader(String name, String value)
name - the given namevalue - the given valuepublic String method()
public String requestURI()
public Object attr(String name)
name - the given namenull if not foundpublic void attr(String name, Object value)
name - the given namevalue - the given valuepublic String param(String name)
name - the given namenull if not foundpublic String pathVar(String name)
name - the given namenull if not foundpublic void pathVars(Map<String,String> pathVars)
pathVars - the specified path varspublic void pathVar(String name, String value)
name - the given namevalue - the given valuepublic void sendError(int sc)
sc - the specified error status codepublic void sendStatus(int sc)
sc - the specified status codepublic void setStatus(int sc)
sc - the specified status codepublic JSONObject requestJSON()
public RequestContext renderJSONPretty(JSONObject json)
json - the specified json objectpublic RequestContext renderJSON()
JsonRenderer with {"sc": false}.public RequestContext renderJSON(JSONObject json)
json - the specified json objectpublic RequestContext renderJSON(boolean sc)
JsonRenderer with {"sc": sc}.sc - the specified scpublic RequestContext renderJSON(int code)
JsonRenderer with {"code": int}.code - the specified codepublic RequestContext renderTrueResult()
public RequestContext renderFalseResult()
public RequestContext renderCode(int code)
code - the specified codepublic RequestContext renderMsg(String msg)
msg - the specified msgpublic RequestContext renderData(Object data)
data - the specified JSON datapublic RequestContext renderPretty()
public RequestContext renderJSONValue(String name, Object obj)
name - the specified nameobj - the specified objectpublic void handle()
public void abort()
public void addHandler(Handler handler)
handler - the specified handlerCopyright © 2009–2019 B3log. All rights reserved.