当前正在浏览的URL

public String getCurrentURL(HttpServletRequest request) {

  String url = "";
  if (request.getQueryString() != null)
   url =
    request
     .getRequestURL()
     .append("?")
     .append(request.getQueryString())
     .toString();
  else if (request.getRequestURL() != null)
   url = request.getRequestURL().toString();

  return URLEncoder.encode(url);
 }

 public String getCurrentURI(HttpServletRequest request) {

  StringBuffer url = new StringBuffer();
  if (request.getQueryString() != null)
   url.append(request.getRequestURI()).append("?").append(
    request.getQueryString());
  else if (request.getRequestURI() != null)
   url.append(request.getRequestURI());

  return url.toString();
 }

你可能感兴趣的:(url)