类 WebUtil


  • public class WebUtil
    extends org.springframework.web.util.WebUtils
    Miscellaneous utilities for web applications.
    从以下版本开始:
    1.0.0
    作者:
    ths
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static String DEFAULT_USER_TYPE  
      static String HEADER_KEY  
      static String HEADER_PREFIX  
      static String UN_KNOWN  
      static String USER_AGENT_HEADER  
      static String USER_TYPE_HEADER_KEY  
      • 从类继承的字段 org.springframework.web.util.WebUtils

        CONTENT_TYPE_CHARSET_PREFIX, DEFAULT_CHARACTER_ENCODING, DEFAULT_WEB_APP_ROOT_KEY, ERROR_EXCEPTION_ATTRIBUTE, ERROR_EXCEPTION_TYPE_ATTRIBUTE, ERROR_MESSAGE_ATTRIBUTE, ERROR_REQUEST_URI_ATTRIBUTE, ERROR_SERVLET_NAME_ATTRIBUTE, ERROR_STATUS_CODE_ATTRIBUTE, FORWARD_CONTEXT_PATH_ATTRIBUTE, FORWARD_PATH_INFO_ATTRIBUTE, FORWARD_QUERY_STRING_ATTRIBUTE, FORWARD_REQUEST_URI_ATTRIBUTE, FORWARD_SERVLET_PATH_ATTRIBUTE, HTML_ESCAPE_CONTEXT_PARAM, INCLUDE_CONTEXT_PATH_ATTRIBUTE, INCLUDE_PATH_INFO_ATTRIBUTE, INCLUDE_QUERY_STRING_ATTRIBUTE, INCLUDE_REQUEST_URI_ATTRIBUTE, INCLUDE_SERVLET_PATH_ATTRIBUTE, RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM, SESSION_MUTEX_ATTRIBUTE, SUBMIT_IMAGE_SUFFIXES, TEMP_DIR_CONTEXT_ATTRIBUTE, WEB_APP_ROOT_KEY_PARAM
    • 构造器概要

      构造器 
      构造器 说明
      WebUtil()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static String getCookieVal​(String name)
      读取cookie
      static String getCookieVal​(javax.servlet.http.HttpServletRequest request, String name)
      读取cookie
      static String getHeader​(String headerKey)
      获取 headerValue
      static String getIp()
      获取ip
      static String getIp​(javax.servlet.http.HttpServletRequest request)
      获取ip
      static javax.servlet.http.HttpServletRequest getRequest()
      获取 HttpServletRequest
      static byte[] getRequestBytes​(javax.servlet.http.HttpServletRequest request)
      获取 request 请求的 byte[] 数组
      static String getRequestParamString​(javax.servlet.http.HttpServletRequest request)
      获取 request 中 json 字符串的内容
      static String getRequestStr​(javax.servlet.http.HttpServletRequest request)
      获取 request 请求内容
      static String getRequestStr​(javax.servlet.http.HttpServletRequest request, byte[] buffer)
      获取 request 请求内容
      static boolean isBody​(org.springframework.web.method.HandlerMethod handlerMethod)
      判断是否ajax请求 spring ajax 返回含有 ResponseBody 或者 RestController注解
      static void removeCookie​(javax.servlet.http.HttpServletResponse response, String key)
      清除 某个指定的cookie
      static void renderJson​(javax.servlet.http.HttpServletResponse response, Object result)
      返回json
      static void renderJson​(javax.servlet.http.HttpServletResponse response, Object result, String contentType)
      返回json
      static void setCookie​(javax.servlet.http.HttpServletResponse response, String name, String value, int maxAgeInSeconds)
      设置cookie
      • 从类继承的方法 org.springframework.web.util.WebUtils

        clearErrorRequestAttributes, exposeErrorRequestAttributes, findParameterValue, findParameterValue, getCookie, getDefaultHtmlEscape, getNativeRequest, getNativeResponse, getParametersStartingWith, getRealPath, getRequiredSessionAttribute, getResponseEncodedHtmlEscape, getSessionAttribute, getSessionId, getSessionMutex, getTempDir, hasSubmitParameter, isIncludeRequest, isSameOrigin, isValidOrigin, parseMatrixVariables, removeWebAppRootSystemProperty, setSessionAttribute, setWebAppRootSystemProperty
    • 构造器详细资料

      • WebUtil

        public WebUtil()
    • 方法详细资料

      • isBody

        public static boolean isBody​(org.springframework.web.method.HandlerMethod handlerMethod)
        判断是否ajax请求 spring ajax 返回含有 ResponseBody 或者 RestController注解
        参数:
        handlerMethod - HandlerMethod
        返回:
        是否ajax请求
      • getCookieVal

        @Nullable
        public static String getCookieVal​(String name)
        读取cookie
        参数:
        name - cookie name
        返回:
        cookie value
      • getCookieVal

        @Nullable
        public static String getCookieVal​(javax.servlet.http.HttpServletRequest request,
                                          String name)
        读取cookie
        参数:
        request - HttpServletRequest
        name - cookie name
        返回:
        cookie value
      • removeCookie

        public static void removeCookie​(javax.servlet.http.HttpServletResponse response,
                                        String key)
        清除 某个指定的cookie
        参数:
        response - HttpServletResponse
        key - cookie key
      • setCookie

        public static void setCookie​(javax.servlet.http.HttpServletResponse response,
                                     String name,
                                     @Nullable
                                     String value,
                                     int maxAgeInSeconds)
        设置cookie
        参数:
        response - HttpServletResponse
        name - cookie name
        value - cookie value
        maxAgeInSeconds - maxage
      • getRequest

        public static javax.servlet.http.HttpServletRequest getRequest()
        获取 HttpServletRequest
        返回:
        {HttpServletRequest}
      • getHeader

        public static String getHeader​(String headerKey)
        获取 headerValue
        参数:
        headerKey - headerKey
        返回:
        {headerValue}
      • renderJson

        public static void renderJson​(javax.servlet.http.HttpServletResponse response,
                                      Object result)
        返回json
        参数:
        response - HttpServletResponse
        result - 结果对象
      • renderJson

        public static void renderJson​(javax.servlet.http.HttpServletResponse response,
                                      Object result,
                                      String contentType)
        返回json
        参数:
        response - HttpServletResponse
        result - 结果对象
        contentType - contentType
      • getIp

        public static String getIp()
        获取ip
        返回:
        {String}
      • getIp

        @Nullable
        public static String getIp​(javax.servlet.http.HttpServletRequest request)
        获取ip
        参数:
        request - HttpServletRequest
        返回:
        {String}
      • getRequestParamString

        public static String getRequestParamString​(javax.servlet.http.HttpServletRequest request)
        获取 request 中 json 字符串的内容
        参数:
        request - request
        返回:
        字符串内容
      • getRequestStr

        public static String getRequestStr​(javax.servlet.http.HttpServletRequest request)
                                    throws IOException
        获取 request 请求内容
        参数:
        request - request
        返回:
        String
        抛出:
        IOException - IOException
      • getRequestBytes

        public static byte[] getRequestBytes​(javax.servlet.http.HttpServletRequest request)
                                      throws IOException
        获取 request 请求的 byte[] 数组
        参数:
        request - request
        返回:
        byte[]
        抛出:
        IOException - IOException
      • getRequestStr

        public static String getRequestStr​(javax.servlet.http.HttpServletRequest request,
                                           byte[] buffer)
                                    throws IOException
        获取 request 请求内容
        参数:
        request - request
        buffer - buffer
        返回:
        String
        抛出:
        IOException - IOException