public class HttpUtils extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
HttpUtils.Request |
| 构造器和说明 |
|---|
HttpUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addCookie(String name,
String value,
javax.servlet.http.HttpServletResponse response)
不存储cookie,浏览器关闭则删除cookie
|
static void |
addCookie(String name,
String value,
Integer maxAge,
javax.servlet.http.HttpServletResponse response) |
static String |
addParams2Url(String url,
String params)
给指定的url增加参数字符窜,根据url的“?”
|
static String |
assembleParams(Map<?,?> params,
Collection<?> jsonKeys,
String... excludeKeys)
把参数转换成url中的键值对
|
static Map<String,String> |
convertQueryParams2Map(String query) |
static void |
download(File srcFile,
String filename,
javax.servlet.http.HttpServletResponse response)
下载文件
|
static void |
download(InputStream inputStream,
String filename,
javax.servlet.http.HttpServletResponse response)
下载文件
|
static String |
getBasePath(javax.servlet.http.HttpServletRequest request)
获取请求的根路径
http://www.xx.com ==> http://www.xx.com
http://www.xx.com/a/b.html ==> http://www.xx.com
http://localhost:8080/test/a/b.html ==> http://localhost:8080/test
|
static javax.servlet.http.Cookie |
getCookie(String cookieName,
javax.servlet.http.HttpServletRequest request) |
static String |
getCookieVal(String cookieName,
javax.servlet.http.HttpServletRequest request) |
static <T> T |
getCookieVal(String cookieName,
javax.servlet.http.HttpServletRequest request,
Class<T> clazz) |
static String |
getFullRequestUri(javax.servlet.http.HttpServletRequest request,
boolean encode,
String... excludeKeys)
获取请求地址信息,包含参数。
|
static String |
getFullRequestUrl(javax.servlet.http.HttpServletRequest request,
boolean encode,
String... excludeKeys)
获取请求地址信息,包含参数。
|
static String |
getIpAddr(javax.servlet.http.HttpServletRequest request)
获得客户端ip
|
static String |
getParticularPath(javax.servlet.http.HttpServletRequest request)
获取请求特有的path
http://www.xx.com ==> "" http://www.xx.com/a/b.html ==> /a/b.html http://localhost:8080/test/a/b.html ==> /a/b.html |
static String[] |
getParticularPaths(javax.servlet.http.HttpServletRequest request)
http://www.xxx.com/shop/list.do ==> [shop, list]
http://www.xxx.com/js/util.js ==> [js, util]
|
static String |
getRequestParams(javax.servlet.http.HttpServletRequest request,
boolean encode,
String... excludeKeys)
获取请求的参数 例:name=wangxj&shop=wxj
|
static String |
getRequestUrlAndParams(javax.servlet.http.HttpServletRequest request)
获取请求地址信息,包含参数
数组会转换成[1,2]形式
|
static String |
getShortPath(javax.servlet.http.HttpServletRequest request)
获取简短的请求路径
http://www.xx.com ==> "" http://www.xx.com/a/b.html ==> /a/b http://localhost:8080/test/a/b.html ==> /a/b |
static boolean |
isAjaxRequest(javax.servlet.http.HttpServletRequest request)
判断是否为ajax请求
|
static boolean |
isResponseHtml(javax.servlet.http.HttpServletRequest request)
判断是否为ajax请求
|
static boolean |
isResponseJson(javax.servlet.http.HttpServletRequest request)
判断是否为ajax请求
|
static void |
outHtml(Object obj,
javax.servlet.http.HttpServletResponse response)
以HTML格式输出
|
static void |
outHtml(String str,
javax.servlet.http.HttpServletResponse response)
以HTML格式输出
|
static void |
outHtmlJs(String str,
javax.servlet.http.HttpServletResponse response)
以HTML格式输出JS,给str 头尾自动加上<script type="text/javascript"> </script>
|
static void |
outJs(Object obj,
javax.servlet.http.HttpServletResponse response)
以js格式输出
|
static void |
outJs(String str,
javax.servlet.http.HttpServletResponse response)
以js格式输出
|
static void |
outJson(Object obj,
javax.servlet.http.HttpServletResponse response)
以Json格式输出
|
static void |
outJson(String str,
javax.servlet.http.HttpServletResponse response)
以Json格式输出
|
static void |
outObject(Object obj,
javax.servlet.http.HttpServletResponse response)
把对象输出到客户端
|
static void |
outPlainString(Object obj,
javax.servlet.http.HttpServletResponse response)
以文本的格式输出
|
static void |
outPlainString(String str,
javax.servlet.http.HttpServletResponse response)
以文本的格式输出
|
static void |
outString(String str,
javax.servlet.http.HttpServletResponse response)
把字符输出到客户端
|
static void |
outXml(Object obj,
javax.servlet.http.HttpServletResponse response)
以XML格式输出
|
static void |
outXml(String str,
javax.servlet.http.HttpServletResponse response)
以XML格式输出
|
static void |
removeCookie(String cookieName,
javax.servlet.http.HttpServletResponse response) |
public static String getIpAddr(javax.servlet.http.HttpServletRequest request)
request - public static String getRequestUrlAndParams(javax.servlet.http.HttpServletRequest request)
public static String getFullRequestUri(javax.servlet.http.HttpServletRequest request, boolean encode, String... excludeKeys) throws UnsupportedEncodingException
encode - 编码参数UnsupportedEncodingExceptionpublic static String getFullRequestUrl(javax.servlet.http.HttpServletRequest request, boolean encode, String... excludeKeys) throws UnsupportedEncodingException
encode - 编码参数UnsupportedEncodingExceptionpublic static String getParticularPath(javax.servlet.http.HttpServletRequest request)
request - public static String getShortPath(javax.servlet.http.HttpServletRequest request)
request - public static String getBasePath(javax.servlet.http.HttpServletRequest request)
request - public static String[] getParticularPaths(javax.servlet.http.HttpServletRequest request)
request - public static String getRequestParams(javax.servlet.http.HttpServletRequest request, boolean encode, String... excludeKeys) throws UnsupportedEncodingException
request - UnsupportedEncodingExceptionpublic static String assembleParams(Map<?,?> params, Collection<?> jsonKeys, String... excludeKeys) throws com.fasterxml.jackson.core.JsonGenerationException, com.fasterxml.jackson.databind.JsonMappingException, IOException
params - jsonKeys - 指定哪些key的值用json解析excludeKeys - 排除的keyIOExceptioncom.fasterxml.jackson.databind.JsonMappingExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic static String addParams2Url(String url, String params)
url - params - public static boolean isAjaxRequest(javax.servlet.http.HttpServletRequest request)
request - public static boolean isResponseJson(javax.servlet.http.HttpServletRequest request)
request - public static boolean isResponseHtml(javax.servlet.http.HttpServletRequest request)
request - public static void addCookie(String name, String value, javax.servlet.http.HttpServletResponse response)
name - value - response - public static void addCookie(String name, String value, Integer maxAge, javax.servlet.http.HttpServletResponse response)
name - value - maxAge - 单位/秒response - public static javax.servlet.http.Cookie getCookie(String cookieName, javax.servlet.http.HttpServletRequest request)
public static String getCookieVal(String cookieName, javax.servlet.http.HttpServletRequest request)
public static <T> T getCookieVal(String cookieName, javax.servlet.http.HttpServletRequest request, Class<T> clazz)
public static void removeCookie(String cookieName, javax.servlet.http.HttpServletResponse response)
public static void outString(String str, javax.servlet.http.HttpServletResponse response)
public static void outObject(Object obj, javax.servlet.http.HttpServletResponse response)
public static void outPlainString(String str, javax.servlet.http.HttpServletResponse response)
public static void outPlainString(Object obj, javax.servlet.http.HttpServletResponse response)
public static void outJs(String str, javax.servlet.http.HttpServletResponse response)
public static void outJs(Object obj, javax.servlet.http.HttpServletResponse response)
public static void outXml(String str, javax.servlet.http.HttpServletResponse response)
public static void outXml(Object obj, javax.servlet.http.HttpServletResponse response)
public static void outHtml(String str, javax.servlet.http.HttpServletResponse response)
public static void outHtmlJs(String str, javax.servlet.http.HttpServletResponse response)
public static void outHtml(Object obj, javax.servlet.http.HttpServletResponse response)
public static void outJson(String str, javax.servlet.http.HttpServletResponse response)
public static void outJson(Object obj, javax.servlet.http.HttpServletResponse response)
public static void download(File srcFile, String filename, javax.servlet.http.HttpServletResponse response) throws IOException
srcFile - 下载的源文件filename - 下载到客户端的文件名response - IOExceptionpublic static void download(InputStream inputStream, String filename, javax.servlet.http.HttpServletResponse response) throws IOException
inputStream - 输入流,此流需要自己关闭,此方法不会帮你关闭filename - 下载到客户端的文件名IOExceptionCopyright © 2016. All rights reserved.