1. import javax.servlet.http.HttpServletRequest;
    2. import java.util.Iterator;
    3. import java.util.Map;
    4. import java.util.Set;
    5. public class HttpServletUtils {
    6. /**
    7. * 获取完整请求路径,带请求参数
    8. *
    9. * @param request
    10. * @return
    11. */
    12. public static String getFullPath(HttpServletRequest request) {
    13. StringBuffer uri = request.getRequestURL();
    14. String url = uri.toString();
    15. // 获取所有请求,返回 Map 集合
    16. Map<String, String[]> map = request.getParameterMap();
    17. Set<Map.Entry<String, String[]>> entry = map.entrySet();
    18. Iterator<Map.Entry<String, String[]>> iterator = entry.iterator();
    19. // 遍历集合
    20. StringBuffer sb = new StringBuffer();
    21. while (iterator.hasNext()) {
    22. Map.Entry<String, String[]> item = iterator.next();
    23. //请求名
    24. String key = item.getKey();
    25. //请求值
    26. for (String value : item.getValue()) {
    27. // 拼接每个请求参数 key=value&
    28. sb.append(key + "=" + value + "&");
    29. }
    30. }
    31. String string = sb.toString();
    32. if (StringUtils.isNotBlank(string)){
    33. // 拼接 URL, URL?key=value&key=value& 并且去掉最后一个 &
    34. url = url + "?" + string.substring(0, string.lastIndexOf("&"));
    35. }
    36. return url;
    37. }
    38. }