Commit a30cd39c authored by yanzg's avatar yanzg

异常处理显示

parent 37cb42d3
......@@ -3,13 +3,15 @@ package com.yanzuoguang.cloud.helper;
import com.yanzuoguang.token.TokenHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.helper.UrlHelper;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
......@@ -44,7 +46,7 @@ public class CookiesHelper {
* @param key 键值
* @return 缓存的键值
*/
public static String get(String key) {
public static String get(String key) throws UnsupportedEncodingException {
HttpServletRequest request = getRequest();
Map<String, String> map = new HashMap<>();
int keyLength = 0;
......@@ -56,7 +58,7 @@ public class CookiesHelper {
keyLength = StringHelper.toInt(item.getValue());
continue;
} else {
return UrlHelper.decoding(item.getValue(), CHARSET);
return URLDecoder.decode(item.getValue(), CHARSET);
}
} else if (item.getName().startsWith(key)) {
map.put(key, item.getValue());
......@@ -72,7 +74,7 @@ public class CookiesHelper {
}
sb.append(map.get(itemKey));
}
return UrlHelper.decoding(sb.toString(), CHARSET);
return URLDecoder.decode(sb.toString(), CHARSET);
}
/**
......@@ -81,9 +83,9 @@ public class CookiesHelper {
* @param key 键
* @param value 值
*/
public static void set(String key, String value) {
public static void set(String key, String value) throws UnsupportedEncodingException {
HttpServletResponse response = getResposne();
String toValue = UrlHelper.encoding(value, CHARSET);
String toValue = URLEncoder.encode(value, CHARSET);
if (toValue.length() < ITEM_MAX_SIZE) {
// 创建cookie对象
Cookie cookie = new Cookie(key, value);
......@@ -135,7 +137,7 @@ public class CookiesHelper {
/**
* 登录结束处理
*/
public static void tokenFinish() {
public static void tokenFinish() throws UnsupportedEncodingException {
String tokenResponse = TokenHelper.getTokenString();
if (!StringHelper.isEmpty(tokenResponse)) {
set(TOKEN_STRING_KEY, tokenResponse);
......@@ -146,7 +148,7 @@ public class CookiesHelper {
/**
* 登录初始化
*/
public static void tokenInit() {
public static void tokenInit() throws UnsupportedEncodingException {
String tokenRequest = get(CookiesHelper.TOKEN_STRING_KEY);
if (!StringHelper.isEmpty(tokenRequest)) {
TokenHelper.setTokenString(tokenRequest);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment