public final class WebUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
AUTH_COOKIE |
static String |
AUTH_HEADER
authorization
|
static String |
AUTH_PARAME |
static String |
COOKIE_ROOT_PATH |
static String |
INCLUDE_CONTEXT_PATH_ATTRIBUTE |
| 构造器和说明 |
|---|
WebUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addCookie(javax.servlet.http.HttpServletResponse response,
String name,
String value)
设置cookie
|
static void |
addCookie(javax.servlet.http.HttpServletResponse resp,
String name,
String value,
String path,
int maxAge)
设置cookie
|
static void |
cors(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
ross-Origin Resource Sharing
|
static javax.servlet.http.Cookie |
createCookie(String name,
String value,
String path,
int maxAge)
Creates a cookie
|
static void |
delCookie(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String name) |
static void |
delCookie(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String path,
String name)
Delete the cookie by spec name
|
static void |
download(javax.servlet.http.HttpServletResponse resp,
byte[] data,
String filename) |
static void |
download(javax.servlet.http.HttpServletResponse resp,
byte[] data,
String filename,
String charset,
boolean isGzip,
boolean withBom)
Response as a stream attachment
|
static void |
download(javax.servlet.http.HttpServletResponse resp,
InputStream input,
String filename)
response to input stream
|
static void |
download(javax.servlet.http.HttpServletResponse resp,
InputStream input,
String filename,
String charset,
boolean isGzip,
boolean withBom)
Response as a stream attachment
|
static LiteDevice |
getClientDevice(javax.servlet.http.HttpServletRequest req)
获取客户端设备类型
|
static String |
getClientIp(javax.servlet.http.HttpServletRequest req)
获取客户端ip
|
static String |
getContextPath(javax.servlet.http.HttpServletRequest request)
Return the context path for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
static String |
getContextPath(javax.servlet.ServletContext context) |
static String |
getCookie(javax.servlet.http.HttpServletRequest req,
String name)
get cookie value
|
static Map<String,String> |
getParams(javax.servlet.http.HttpServletRequest request)
Gets the http servlet request parameters
the parameter value is
String type
if is array parameter, then the value is based-join on "," as String |
static String |
getSessionTrace(javax.servlet.http.HttpServletRequest request)
会话跟踪
|
static String |
getText(javax.servlet.http.HttpServletRequest request) |
static String |
getText(javax.servlet.http.HttpServletRequest request,
String charset)
get the text string from request input stream
|
static String |
getUrlSuffix(javax.servlet.http.HttpServletRequest req)
获取请求地址后缀名
|
static boolean |
isAjax(javax.servlet.http.HttpServletRequest req)
判断是否ajax请求
|
static String |
normalize(String path)
Normalize a relative URI path that may have relative values ("/./",
"/../", and so on ) it it.
|
static String |
normalize(String path,
boolean replaceBackSlash)
Normalize a relative URI path that may have relative values ("/./",
"/../", and so on ) it it.
|
static void |
respJson(javax.servlet.http.HttpServletResponse resp,
Object data)
响应json数据
|
static void |
respJson(javax.servlet.http.HttpServletResponse resp,
Object data,
String charset) |
static void |
respJsonp(javax.servlet.http.HttpServletResponse response,
String callback,
Object data) |
static void |
respJsonp(javax.servlet.http.HttpServletResponse resp,
String callback,
Object data,
String charset)
响应jsonp数据
|
static void |
response(javax.servlet.http.HttpServletResponse resp,
byte[] data,
ContentType contentType,
boolean isGzip)
响应数据流,如图片数据
response(resp, image_byte_array, ContentType.IMAGE_JPEG.value(), false);
|
static void |
response(javax.servlet.http.HttpServletResponse resp,
ContentType contentType,
String text,
String charset)
响应数据到请求客户端
|
static void |
response(javax.servlet.http.HttpServletResponse resp,
InputStream input,
ContentType contentType,
boolean isGzip)
响应数据流,如图片数据
response(resp, image_file_input_stream, ContentType.IMAGE_JPEG.value(), false);
|
static void |
setSessionTrace(javax.servlet.http.HttpServletResponse response,
String token)
会话跟踪
|
static String |
userAgent(javax.servlet.http.HttpServletRequest req)
Returns the web browser user-agent
|
static String |
xssReplace(String text) |
public static final String INCLUDE_CONTEXT_PATH_ATTRIBUTE
public static Map<String,String> getParams(javax.servlet.http.HttpServletRequest request)
String type
if is array parameter, then the value is based-join on "," as Stringrequest - public static String getText(javax.servlet.http.HttpServletRequest request)
public static String getText(javax.servlet.http.HttpServletRequest request, String charset)
request - the HttpServletRequestcharset - the string encodingpublic static String getClientIp(javax.servlet.http.HttpServletRequest req)
req - public static LiteDevice getClientDevice(javax.servlet.http.HttpServletRequest req)
public static boolean isAjax(javax.servlet.http.HttpServletRequest req)
req - public static String userAgent(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static void response(javax.servlet.http.HttpServletResponse resp,
ContentType contentType,
String text,
String charset)
resp - contentType - text - charset - public static void respJson(javax.servlet.http.HttpServletResponse resp,
Object data)
resp - data - public static void respJson(javax.servlet.http.HttpServletResponse resp,
Object data,
String charset)
public static void respJsonp(javax.servlet.http.HttpServletResponse response,
String callback,
Object data)
public static void respJsonp(javax.servlet.http.HttpServletResponse resp,
String callback,
Object data,
String charset)
resp - callback - data - charset - public static void download(javax.servlet.http.HttpServletResponse resp,
byte[] data,
String filename)
public static void download(javax.servlet.http.HttpServletResponse resp,
byte[] data,
String filename,
String charset,
boolean isGzip,
boolean withBom)
resp - the HttpServletResponsedata - the resp byte array datafilename - the resp attachment filenamecharset - the attachment filename encodingisGzip - true to use gzip compresswithBom - true with bom headerpublic static void download(javax.servlet.http.HttpServletResponse resp,
InputStream input,
String filename)
resp - the HttpServletResponseinput - the input streamfilename - the resp attachment filenamepublic static void download(javax.servlet.http.HttpServletResponse resp,
InputStream input,
String filename,
String charset,
boolean isGzip,
boolean withBom)
resp - the HttpServletResponseinput - the input streamfilename - the resp attachment filenamecharset - the attachment filename encodingisGzip - true to use gzip compresswithBom - true with bom headerpublic static void response(javax.servlet.http.HttpServletResponse resp,
byte[] data,
ContentType contentType,
boolean isGzip)
resp - the HttpServletResponsedata - the byte array datacontentType - the content-typeisGzip - whether to encode gzippublic static void response(javax.servlet.http.HttpServletResponse resp,
InputStream input,
ContentType contentType,
boolean isGzip)
resp - the HttpServletResponseinput - the input streamcontentType - the content-typeisGzip - whether to encode gzippublic static void cors(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
req - the HttpServletRequestresp - the HttpServletResponsepublic static String getUrlSuffix(javax.servlet.http.HttpServletRequest req)
req - public static String getCookie(javax.servlet.http.HttpServletRequest req, String name)
req - name - public static void delCookie(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String name)
public static void delCookie(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String path,
String name)
req - the HttpServletRequestresp - the HttpServletResponsepath - the cookie pathname - the cookie namepublic static void addCookie(javax.servlet.http.HttpServletResponse response,
String name,
String value)
response - name - value - public static void addCookie(javax.servlet.http.HttpServletResponse resp,
String name,
String value,
String path,
int maxAge)
resp - name - value - path - maxAge - public static javax.servlet.http.Cookie createCookie(String name, String value, String path, int maxAge)
name - value - path - maxAge - public static void setSessionTrace(javax.servlet.http.HttpServletResponse response,
String token)
public static String getSessionTrace(javax.servlet.http.HttpServletRequest request)
public static String getContextPath(javax.servlet.ServletContext context)
public static String getContextPath(javax.servlet.http.HttpServletRequest request)
As the value returned by request.getContextPath() is not
decoded by the servlet container, this method will decode it.
request - current HTTP requestpublic static String normalize(String path)
path - Relative path to be normalizedpublic static String normalize(String path, boolean replaceBackSlash)
path - Relative path to be normalizedreplaceBackSlash - Should '\\' be replaced with '/'Copyright © 2023. All rights reserved.