public abstract class Context extends Object
| Modifier and Type | Field and Description |
|---|---|
protected Charset |
charset |
Throwable |
errors
用于在处理链中透传处理错误
|
Object |
result
用于在处理链中透传处理结果
|
protected SessionState |
sessionState |
| Constructor and Description |
|---|
Context() |
| Modifier and Type | Method and Description |
|---|---|
String |
accept()
获取 Accept 头信息
|
void |
accept(String acceptNew) |
String |
acceptNew()
获取新的 Accept 头信息
|
Action |
action()
获取当前动作
|
abstract void |
asyncComplete()
异步完成
|
abstract void |
asyncListener(ContextAsyncListener listener)
异步监听
|
void |
asyncStart()
异步开始
|
abstract void |
asyncStart(long timeout,
Runnable runnable)
异步开始
|
abstract boolean |
asyncStarted()
异步已开始
|
abstract boolean |
asyncSupported()
是否支持异步
|
<T> T |
attr(String name)
获取上下文特性
|
Map<String,Object> |
attrMap()
获取自定义特性并转为Map
|
Collection<String> |
attrNames()
获取上下文特性的名字集合
|
<T> T |
attrOrDefault(String name,
T def)
获取上下文特性
|
void |
attrsClear()
清除所有上下文特性
|
void |
attrSet(Map<String,Object> map)
设置上下文特性
|
void |
attrSet(String name,
Object val)
设置上下文特性
|
boolean |
autoMultipart()
是否自动解析分段内容
|
void |
autoMultipart(boolean auto)
设置是否自动解析分段内容
|
String |
body()
获取body内容
|
String |
body(String charset)
获取body内容
|
byte[] |
bodyAsBytes()
获取body内容为byte[]
|
abstract InputStream |
bodyAsStream()
获取body内容为Stream
|
String |
bodyNew()
获取新的body
|
void |
bodyNew(String bodyNew)
设置新的body
|
void |
cacheControl(String strategy)
设置缓存控制
|
void |
charset(String charset)
设置字符集
|
abstract void |
close()
关闭响应(一些特殊的boot才有效)
|
abstract String |
contentCharset()
获取获取编码类型
|
abstract long |
contentLength()
获取内容长度
|
void |
contentLength(long size)
设置内容长度
|
abstract String |
contentType()
获取内容类型
|
void |
contentType(String contentType)
设置内容类型
|
protected abstract void |
contentTypeDoSet(String contentType) |
String |
contentTypeNew()
获取设置的新内容类型
|
Object |
controller()
获取当前控制器
|
String |
cookie(String name)
获取 cookie
|
abstract MultiMap<String> |
cookieMap()
获取小饼字典集合
|
Collection<String> |
cookieNames()
获取所有小饼的名字集合
|
String |
cookieOrDefault(String name,
String def)
获取 cookie
|
void |
cookieRemove(String name)
移徐 cookie
|
abstract void |
cookieSet(Cookie cookie)
设置 cookie
|
void |
cookieSet(String name,
String val)
设置 cookie
|
void |
cookieSet(String name,
String val,
int maxAge)
设置 cookie
|
void |
cookieSet(String name,
String val,
String domain,
int maxAge)
设置 cookie
|
void |
cookieSet(String name,
String val,
String domain,
String path,
int maxAge)
设置 cookie
|
String[] |
cookieValues(String name)
获取 cookie (多值)
|
static Context |
current()
获取当前线程的上下文
|
UploadedFile |
file(String name)
获取上传文件
|
abstract MultiMap<UploadedFile> |
fileMap()
获取上传文件字典集合
|
Set<String> |
fileNames()
获取所有文件的名字集合
|
abstract void |
filesDelete()
删除所有上传文件
|
UploadedFile[] |
fileValues(String name)
获取上传文件数组
|
abstract void |
flush()
冲刷
|
void |
forward(String pathNew)
转发
|
boolean |
getHandled()
获取处理状态
|
Locale |
getLocale()
获取地区
|
boolean |
getRendered()
获取渲染状态
|
String |
header(String name)
获取 header
|
abstract void |
headerAdd(String name,
String val)
添加 header
|
abstract MultiMap<String> |
headerMap()
获取头字典集合
|
Collection<String> |
headerNames()
获取所有头的名字集合
|
abstract Collection<String> |
headerNamesOfResponse()
获取响应 headerNames
|
abstract String |
headerOfResponse(String name)
获取响应 header
|
String |
headerOrDefault(String name,
String def)
获取 header
|
abstract void |
headerSet(String name,
String val)
设置 header
|
String[] |
headerValues(String name)
获取 header (多值)
|
abstract Collection<String> |
headerValuesOfResponse(String name)
获取响应 header
|
boolean |
isFormUrlencoded()
是否为编码窗体
|
abstract boolean |
isHeadersSent()
是否头部已发送
|
boolean |
isMultipart()
是否为分段内容
|
boolean |
isMultipartFormData()
是否为分段表单数据
|
abstract boolean |
isSecure()
是否为 ssl 请求
|
void |
keepAlive(int timeout)
设置保持连接
|
Handler |
mainHandler()
获取当前主处理器
|
abstract String |
method()
获取请求方法
|
abstract void |
output(byte[] bytes)
输出 字节数组
|
abstract void |
output(InputStream stream)
输出 流对象
|
void |
output(String str)
输出 字符串
|
void |
output(Throwable ex)
输出 异常对象
|
abstract void |
outputAsFile(DownloadedFile file)
输出为文件
|
abstract void |
outputAsFile(File file)
输出为文件
|
void |
outputAsHtml(String html)
输出为html文本
|
void |
outputAsJson(String json)
输出为json文本
|
abstract OutputStream |
outputStream()
获取输出流
|
abstract GZIPOutputStream |
outputStreamAsGzip()
获取输出流 gzip 模式
|
String |
param(String name)
获取参数
|
<T> T |
paramAsBean(Class<T> type)
获取参数并转为Bean
|
BigDecimal |
paramAsDecimal(String name)
获取参数并转为BigDecimal
|
BigDecimal |
paramAsDecimal(String name,
BigDecimal def)
获取参数并转为BigDecimal
|
double |
paramAsDouble(String name)
获取参数并转为double
|
double |
paramAsDouble(String name,
double def)
获取参数并转为double
|
int |
paramAsInt(String name)
获取参数并转为int
|
int |
paramAsInt(String name,
int def)
获取参数并转为int
|
long |
paramAsLong(String name)
获取参数并转为long
|
long |
paramAsLong(String name,
long def)
获取参数并转为long
|
abstract MultiMap<String> |
paramMap()
获取参数字典集合
|
Collection<String> |
paramNames()
获取所有参数的名字集合
|
String |
paramOrDefault(String key,
String def)
获取参数或默认
|
String[] |
paramValues(String name)
获取参数数组
|
abstract String |
path() |
String |
pathAsLower()
获取请求的URI路径并大写
|
String |
pathAsUpper()
获取请求的URI路径并大写
|
Map<String,String> |
pathMap(String expr)
获取请求的URI路径变量,根据路径表达式
|
String |
pathNew()
获取新路径,不存在则返回原路径
|
void |
pathNew(String pathNew)
设置新路径
|
abstract String |
protocol()
获取请求协议
|
String |
protocolAsUpper()
获取请求协议并大写
|
Object |
pull(Class<?> clz)
拉取
|
abstract String |
queryString()
获取查询字符串
|
String |
realIp()
获取客户端真实IP
|
void |
redirect(String url)
跳转地址
|
abstract void |
redirect(String url,
int code)
跳转地址
|
String |
referer()
获取请求的Referer
|
abstract String |
remoteIp()
获取远程IP
|
abstract int |
remotePort()
获取远程Port
|
boolean |
remoting()
是否为远程调用
|
void |
remotingSet(boolean remoting) |
void |
render(Object obj)
渲染数据(不能重写,避免死循环)
|
void |
render(String view,
Map<String,?> data)
渲染数据
|
String |
renderAndReturn(Object obj)
渲染数据并返回
|
abstract Object |
request()
获取请求对象
|
abstract Object |
response()
获取响应对象
|
void |
returnValue(Object obj)
返回值
|
Object |
session(String name) |
abstract <T> T |
session(String name,
Class<T> clz)
获取 session 状态
|
abstract double |
sessionAsDouble(String name)
获取 session 状态,并以 double 型输出
|
abstract double |
sessionAsDouble(String name,
double def)
获取 session 状态,并以 double 型输出
|
abstract int |
sessionAsInt(String name)
获取 session 状态,并以 int 型输出
|
abstract int |
sessionAsInt(String name,
int def)
获取 session 状态,并以 int 型输出
|
abstract long |
sessionAsLong(String name)
获取 session 状态,并以 long 型输出
|
abstract long |
sessionAsLong(String name,
long def)
获取 session 状态,并以 long 型输出
|
abstract void |
sessionClear()
清空 session 状态
|
abstract String |
sessionId()
获取 sessionId
|
abstract <T> T |
sessionOrDefault(String name,
T def)
获取 session 状态(类型转换,存在风险)
|
abstract void |
sessionRemove(String name)
移除 session 状态
|
abstract void |
sessionReset()
重置 session 状态
|
abstract void |
sessionSet(String name,
Object val)
设置 session 状态
|
SessionState |
sessionState()
获取 sessionState
|
SessionState |
sessionState(boolean create)
获取 sessionState
|
void |
setHandled(boolean handled)
设置处理状态
|
void |
setLocale(Locale locale)
设置地区
|
void |
setRendered(boolean rendered)
设置渲染状态
|
abstract int |
status()
获取输出状态
|
void |
status(int status)
设置输出状态
|
protected abstract void |
statusDoSet(int status) |
abstract URI |
uri()
获取请求的URI
|
abstract String |
url()
获取请求的URL字符串
|
String |
userAgent()
获取请求的UA
|
protected SessionState sessionState
protected Charset charset
public static Context current()
public Locale getLocale()
public void setLocale(Locale locale)
public void setHandled(boolean handled)
public boolean getHandled()
public void setRendered(boolean rendered)
public boolean getRendered()
public abstract boolean isHeadersSent()
public abstract Object request()
public abstract String remoteIp()
public abstract int remotePort()
public String realIp()
public boolean autoMultipart()
public void autoMultipart(boolean auto)
public boolean isFormUrlencoded()
public boolean isMultipart()
public boolean isMultipartFormData()
public abstract String method()
public abstract String protocol()
public String protocolAsUpper()
public abstract URI uri()
public abstract String path()
public void pathNew(String pathNew)
public String pathNew()
public String pathAsUpper()
public String pathAsLower()
public abstract boolean isSecure()
public String userAgent()
public String referer()
public abstract String url()
public abstract long contentLength()
public abstract String contentType()
public abstract String contentCharset()
public abstract String queryString()
public String accept()
public void accept(String acceptNew)
public String acceptNew()
public String body() throws IOException
IOExceptionpublic String body(String charset) throws IOException
IOExceptionpublic String bodyNew() throws IOException
IOExceptionpublic void bodyNew(String bodyNew)
public byte[] bodyAsBytes()
throws IOException
IOExceptionpublic abstract InputStream bodyAsStream() throws IOException
IOExceptionpublic int paramAsInt(String name)
public int paramAsInt(String name, int def)
public long paramAsLong(String name)
public long paramAsLong(String name, long def)
public double paramAsDouble(String name)
public double paramAsDouble(String name, double def)
public BigDecimal paramAsDecimal(String name)
public BigDecimal paramAsDecimal(String name, BigDecimal def)
public <T> T paramAsBean(Class<T> type)
public Collection<String> paramNames()
@Nullable public UploadedFile[] fileValues(String name)
name - 文件名@Nullable public UploadedFile file(String name) throws IOException
name - 文件名IOExceptionpublic abstract void filesDelete()
throws IOException
IOExceptionpublic abstract MultiMap<UploadedFile> fileMap()
public String cookieOrDefault(String name, String def)
name - cookie名def - 默认值public Collection<String> cookieNames()
public String headerOrDefault(String name, String def)
name - header名@Nullable public String[] headerValues(String name)
name - header名public Collection<String> headerNames()
public SessionState sessionState(boolean create)
public SessionState sessionState()
public abstract String sessionId()
public abstract <T> T session(String name, Class<T> clz)
name - 状态名public abstract <T> T sessionOrDefault(String name, @NonNull T def)
name - 状态名public abstract int sessionAsInt(String name)
name - 状态名public abstract int sessionAsInt(String name, int def)
name - 状态名public abstract long sessionAsLong(String name)
name - 状态名public abstract long sessionAsLong(String name, long def)
name - 状态名public abstract double sessionAsDouble(String name)
name - 状态名public abstract double sessionAsDouble(String name, double def)
name - 状态名public abstract void sessionSet(String name, Object val)
name - 状态名val - 值public abstract void sessionRemove(String name)
name - 状态名public abstract void sessionClear()
public abstract void sessionReset()
public abstract Object response()
public void charset(String charset)
public void contentType(String contentType)
public String contentTypeNew()
protected abstract void contentTypeDoSet(String contentType)
public void contentLength(long size)
public void keepAlive(int timeout)
timeout - 超时(单位:秒)public void cacheControl(String strategy)
strategy - 策略public abstract void output(byte[] bytes)
public abstract void output(InputStream stream)
public abstract OutputStream outputStream() throws IOException
IOExceptionpublic abstract GZIPOutputStream outputStreamAsGzip() throws IOException
IOExceptionpublic void output(String str)
public void output(Throwable ex)
public void outputAsJson(String json)
public void outputAsHtml(String html)
public abstract void outputAsFile(DownloadedFile file) throws IOException
IOExceptionpublic abstract void outputAsFile(File file) throws IOException
IOExceptionpublic abstract Collection<String> headerValuesOfResponse(String name)
public abstract Collection<String> headerNamesOfResponse()
public void cookieSet(String name, String val, String domain, String path, int maxAge)
public abstract void cookieSet(Cookie cookie)
public void cookieRemove(String name)
public void redirect(String url)
public abstract void redirect(String url, int code)
public void forward(String pathNew)
public abstract int status()
public void status(int status)
protected abstract void statusDoSet(int status)
public <T> T attrOrDefault(String name, T def)
public Collection<String> attrNames()
public void attrsClear()
public final void render(String view, Map<String,?> data) throws Throwable
Throwablepublic final String renderAndReturn(Object obj) throws Throwable
Throwablepublic boolean remoting()
public void remotingSet(boolean remoting)
public abstract void flush()
throws IOException
IOExceptionpublic abstract void close()
throws IOException
IOExceptionpublic abstract boolean asyncSupported()
public abstract void asyncListener(ContextAsyncListener listener)
public abstract void asyncStart(long timeout,
Runnable runnable)
timeout - 超时runnable - 运行器public void asyncStart()
public abstract boolean asyncStarted()
public abstract void asyncComplete()
Copyright © 2025. All rights reserved.