public class WebUtils
extends java.lang.Object
限定符和类型 | 方法和说明 |
---|---|
static java.io.PrintWriter |
createPrintWriter(javax.servlet.http.HttpServletResponse res)
生成一个打印输出器
|
static java.io.PrintWriter |
createPrintWriter(javax.servlet.http.HttpServletResponse res,
java.lang.String charsetName)
按指定编码生成打印输出器
|
static java.lang.String |
createServletURL(javax.servlet.http.HttpServletRequest req)
生成一个访问Servelt的相对路径
|
static java.util.Map |
createSessionIDParameterMap(javax.servlet.http.HttpServletRequest req)
生成保存参数的map
|
static java.util.Map<java.lang.String,java.lang.Object> |
dealWithExecuteParamMap(java.util.Map<java.lang.String,java.lang.Object> paramMap)
carl:将传进来的参数Map进行处理
将一些json参数分解出来
过滤掉一些内置参数
传进来的参数Map不变
|
static void |
dealWithTemplate(java.lang.String resource,
javax.servlet.http.HttpServletResponse response)
处理一些指定的模板,主要用于替换一个参数等
|
static void |
flushFailureMessage(javax.servlet.http.HttpServletRequest req,
java.io.PrintWriter writer,
int errorCode,
java.lang.String description,
JSONObject compatibleData)
输出标志失败的信息
|
static void |
flushFailureMessageAutoClose(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
int errorCode,
java.lang.String description)
输出标志失败的信息
|
static void |
flushFailureMessageAutoClose(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
int errorCode,
java.lang.String description,
JSONObject compatibleData)
输出标志失败的信息
|
static void |
flushSuccessMessage(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.PrintWriter writer,
JSONArray data)
输出到前端的JSON数组格式的信息,需要手动关闭writer
|
static void |
flushSuccessMessage(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.PrintWriter writer,
JSONObject data)
输出到前端的JSON格式的信息,需要手动关闭writer
|
static void |
flushSuccessMessageAutoClose(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
JSONArray data)
输出到前端的JSON数组格式的信息
|
static void |
flushSuccessMessageAutoClose(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
JSONObject data)
输出到前端的JSON格式的信息
|
static java.lang.String |
getCSSLinks(Calculator ca)
获取需要Import的css, 并返回html标签
|
static java.lang.String |
getCSSLinks(Calculator ca,
ImportJsCssProvider attr)
获取需要Import的css, 并返回html标签
|
static Device |
getDevice(javax.servlet.http.HttpServletRequest req)
根据网络请求判定发起请求的设备
|
static boolean |
getHTTPRequestBoolParameter(javax.servlet.http.HttpServletRequest req,
java.lang.String paraName)
把HTTP请求中指定名字的参数值转化为布尔值
|
static int |
getHTTPRequestIntParameter(javax.servlet.http.HttpServletRequest req,
java.lang.String paraName)
把HTTP请求中指定名字的参数值转化为整数,参数为空或不是整数则返回-1
|
static int |
getHTTPRequestIntParameter(javax.servlet.http.HttpServletRequest req,
java.lang.String paraName,
int defaultValue)
把HTTP请求中指定名字的参数值转化为整数
|
static java.lang.String |
getHTTPRequestParameter(javax.servlet.http.HttpServletRequest req,
java.lang.String... paraNames)
获取第一个不为空的参数
|
static java.lang.String |
getHTTPRequestParameter(javax.servlet.http.HttpServletRequest req,
java.lang.String paraName)
获取HTTP请求中指定名字的参数值
|
static java.lang.String |
getIpAddr(javax.servlet.http.HttpServletRequest req)
获取发起请求的客户端的IP地址
|
static java.lang.String |
getJSLinks(Calculator ca)
获取需要Import的js, 并返回javascript转义字符串
|
static java.lang.String |
getJSLinks(Calculator ca,
ImportJsCssProvider attr)
获取需要Import的js, 并返回javascript转义字符串
|
static java.lang.String |
getJSLinks(Calculator ca,
ImportJsCssProvider attr,
boolean isHtmlTag)
获取需要Import的js, 并返回html标签或者javascript转义字符串
|
static java.util.Locale |
getLocale(javax.servlet.http.HttpServletRequest req)
获取req中的国际化信息
|
static java.lang.String |
getOriginalURL(javax.servlet.http.HttpServletRequest req)
返回发起指定HTTP请求的URL地址
|
static void |
getPageWhenOverflow(javax.servlet.http.HttpServletResponse res,
java.util.Collection addresses)
返回超过并发数时展示给用户作为提醒的页面
|
static java.lang.String |
getReportTitleFromRequest(javax.servlet.http.HttpServletRequest req)
获取模板的显示标题
|
static Format |
getResponseContentFormat(javax.servlet.http.HttpServletRequest req) |
static java.lang.String |
getWebINFPath(javax.servlet.ServletContext servletContext)
兼容各个web服务器getRealPath方法
|
static boolean |
invalidResourcePath(java.lang.String resourcePath)
判断资源文件路径是否有注入风险.
|
static boolean |
isLocalHost(java.lang.String ip)
判断访问模板的IP是否为服务器本机
|
static java.lang.Object |
object2JSONable(java.lang.Object object)
把一个对象变成可转变为JSON对象的值
|
static java.lang.Object |
object2JSONable(java.lang.Object object,
int cellwidth,
int cellheight)
把一个对象变成可转变为JSON对象的值
|
static java.util.Map<java.lang.String,java.lang.Object> |
parameters4SessionIDInfor(javax.servlet.http.HttpServletRequest req)
将HTTPServletRequest中的所有参数都读取出来,存储在一个Map中,返回出去,主要是为了传给SessionIDInfor
|
static java.util.Map<java.lang.String,java.lang.Object> |
parameters4SessionIDInforContainMPCache(javax.servlet.http.HttpServletRequest req)
生成包括移动参数的map
|
static void |
printAsJSON(javax.servlet.http.HttpServletResponse res,
JSONArray ja)
输出JSON类型的字符串
|
static void |
printAsJSON(javax.servlet.http.HttpServletResponse res,
JSONObject jo)
输出JSON类型的字符串
|
static void |
printAsString(javax.servlet.http.HttpServletResponse res,
java.lang.String jo)
输出字符串,一般来说是JSON格式
|
static int |
receivePageNumber(javax.servlet.http.HttpServletRequest req)
从HTTP请求中获取页码信息
|
static ResourceType |
setResourceContentType(java.lang.String resourceName,
javax.servlet.http.HttpServletResponse res)
获取资源文件类型
|
static void |
writeOutTemplate(java.lang.String resource,
javax.servlet.http.HttpServletResponse response,
java.util.Map map)
写出指定的模板
|
public static java.lang.String getHTTPRequestParameter(javax.servlet.http.HttpServletRequest req, java.lang.String paraName)
req
- HTTP请求paraName
- 参数名public static java.lang.String getHTTPRequestParameter(javax.servlet.http.HttpServletRequest req, java.lang.String... paraNames)
req
- HTTP请求paraNames
- 参数列表public static boolean getHTTPRequestBoolParameter(javax.servlet.http.HttpServletRequest req, java.lang.String paraName)
req
- HTTP请求paraName
- 参数名public static int getHTTPRequestIntParameter(javax.servlet.http.HttpServletRequest req, java.lang.String paraName)
req
- HTTP请求paraName
- 参数名public static int getHTTPRequestIntParameter(javax.servlet.http.HttpServletRequest req, java.lang.String paraName, int defaultValue)
req
- HTTP请求paraName
- 参数名defaultValue
- 默认值public static java.lang.String getReportTitleFromRequest(javax.servlet.http.HttpServletRequest req)
req
- HTTP请求public static java.lang.String createServletURL(javax.servlet.http.HttpServletRequest req)
req
- HTTP请求public static java.io.PrintWriter createPrintWriter(javax.servlet.http.HttpServletResponse res) throws java.io.IOException
res
- HTTP响应java.io.IOException
public static void flushSuccessMessageAutoClose(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, JSONObject data) throws java.lang.Exception
req
- HTTP请求res
- HTTP响应data
- 输出到前端的信息java.lang.Exception
- 如果输出信息失败则抛出此异常public static void flushSuccessMessageAutoClose(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, JSONArray data) throws java.lang.Exception
req
- HTTP请求res
- HTTP响应data
- 输出到前端的信息java.lang.Exception
- 如果输出信息失败则抛出此异常public static void flushSuccessMessage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.io.PrintWriter writer, JSONArray data) throws java.lang.Exception
req
- HTTP请求res
- HTTP响应writer
- 输出字符流data
- 输出到前端的信息java.lang.Exception
- 如果输出信息失败则抛出此异常public static void flushSuccessMessage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.io.PrintWriter writer, JSONObject data) throws java.lang.Exception
req
- HTTP请求res
- HTTP响应writer
- 输出字符流data
- 输出到前端的信息java.lang.Exception
- 如果输出信息失败则抛出此异常public static void flushFailureMessageAutoClose(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int errorCode, java.lang.String description) throws java.lang.Exception
req
- HTTP请求res
- HTTP响应errorCode
- 错误码description
- 错误码描述java.lang.Exception
- 如果输出信息失败则抛出此异常public static void flushFailureMessageAutoClose(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int errorCode, java.lang.String description, JSONObject compatibleData) throws java.lang.Exception
req
- HTTP请求res
- HTTP响应errorCode
- 错误码description
- 错误码描述compatibleData
- 兼容信息java.lang.Exception
- 如果输出信息失败则抛出此异常public static void flushFailureMessage(javax.servlet.http.HttpServletRequest req, java.io.PrintWriter writer, int errorCode, java.lang.String description, JSONObject compatibleData) throws java.lang.Exception
req
- HTTP请求writer
- 输出字符流errorCode
- 错误码description
- 错误码描述compatibleData
- 兼容信息java.lang.Exception
- 如果输出信息失败则抛出此异常public static java.io.PrintWriter createPrintWriter(javax.servlet.http.HttpServletResponse res, java.lang.String charsetName) throws java.io.IOException
res
- HTTP响应charsetName
- 编码java.io.IOException
public static void printAsJSON(javax.servlet.http.HttpServletResponse res, JSONObject jo) throws java.lang.Exception
res
- HTTP响应jo
- JSON对象java.lang.Exception
public static void printAsJSON(javax.servlet.http.HttpServletResponse res, JSONArray ja) throws java.lang.Exception
res
- HTTP响应ja
- JSON数组对象java.lang.Exception
public static void printAsString(javax.servlet.http.HttpServletResponse res, java.lang.String jo) throws java.lang.Exception
res
- HTTP响应jo
- JSON样式的字符串java.lang.Exception
public static java.lang.Object object2JSONable(java.lang.Object object) throws JSONException
object
- 原对象JSONException
- 异常public static java.lang.Object object2JSONable(java.lang.Object object, int cellwidth, int cellheight) throws JSONException
object
- 原对象cellwidth
- 宽度kcellheight
- 高度gJSONException
- 异常public static void getPageWhenOverflow(javax.servlet.http.HttpServletResponse res, java.util.Collection addresses) throws java.lang.Exception
res
- HTTP响应addresses
- 已经连接到报表服务器的地址java.lang.Exception
- 异常public static void dealWithTemplate(java.lang.String resource, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
resource
- 模板的路径response
- HTTP响应java.io.IOException
public static void writeOutTemplate(java.lang.String resource, javax.servlet.http.HttpServletResponse response, java.util.Map map) throws java.io.IOException
resource
- 模板路径response
- HTTP响应map
- 用于替换模板中参数的的参数集java.io.IOException
public static boolean invalidResourcePath(java.lang.String resourcePath)
resourcePath
- 资源文件路径public static ResourceType setResourceContentType(java.lang.String resourceName, javax.servlet.http.HttpServletResponse res)
resourceName
- 资源文件路径res
- http响应public static java.util.Map createSessionIDParameterMap(javax.servlet.http.HttpServletRequest req) throws java.lang.Exception
req
- HTTP请求java.lang.Exception
- 异常public static java.util.Map<java.lang.String,java.lang.Object> dealWithExecuteParamMap(java.util.Map<java.lang.String,java.lang.Object> paramMap)
paramMap
- 待处理的mappublic static java.lang.String getWebINFPath(javax.servlet.ServletContext servletContext)
servletContext
- the servletContextpublic static java.util.Map<java.lang.String,java.lang.Object> parameters4SessionIDInforContainMPCache(javax.servlet.http.HttpServletRequest req)
req
- 请求public static java.util.Map<java.lang.String,java.lang.Object> parameters4SessionIDInfor(javax.servlet.http.HttpServletRequest req)
req
- 请求 qpublic static java.lang.String getOriginalURL(javax.servlet.http.HttpServletRequest req)
req
- HTTP请求public static java.lang.String getIpAddr(javax.servlet.http.HttpServletRequest req)
req
- HTTP请求public static boolean isLocalHost(java.lang.String ip)
ip
- IP地址public static int receivePageNumber(javax.servlet.http.HttpServletRequest req)
req
- 请求qpublic static Device getDevice(javax.servlet.http.HttpServletRequest req)
req
- HTTP请求public static Format getResponseContentFormat(javax.servlet.http.HttpServletRequest req)
public static java.util.Locale getLocale(javax.servlet.http.HttpServletRequest req)
req
- HTTP请求public static java.lang.String getCSSLinks(Calculator ca)
ca
- 算子public static java.lang.String getCSSLinks(Calculator ca, ImportJsCssProvider attr)
ca
- 算子attr
- 当前拥有对象public static java.lang.String getJSLinks(Calculator ca)
ca
- 算子public static java.lang.String getJSLinks(Calculator ca, ImportJsCssProvider attr)
ca
- 算子attr
- 当前拥有对象public static java.lang.String getJSLinks(Calculator ca, ImportJsCssProvider attr, boolean isHtmlTag)
ca
- 算子attr
- 当前拥有对象isHtmlTag
- 是否是html标签