获得网站跳转地址

来源:互联网 发布:兰大网络与教育学院 编辑:程序博客网 时间:2024/05/01 17:22
 private String getRequestURL(HttpServletRequest request)throws Exception
    {
      if (request == null) {
        throw new Exception();
      }
      String url = request.getRequestURL().toString() + "?";
      Enumeration<?> em = request.getParameterNames();
      String tempName = "";
 
      StringBuffer sb = new StringBuffer(url);
      while (em.hasMoreElements()) {
        tempName = (String)em.nextElement();
        sb.append(tempName);
        sb.append('=');
        sb.append(request.getParameter(tempName));
        sb.append('&');
      }
      url = sb.toString();
 
      if (url.endsWith("&"))
        url = url.substring(0, url.length() - 1);
      if (url.endsWith("?")) {
        url = url.substring(0, url.length() - 1);
      }
      return url;
    }
原创粉丝点击