<%@page language="java" contentType="text/html;charset=utf-8" session="false"%>
<jsp:forward   page="page2.jsp"/><%@page language="java" contentType="text/html;charset=utf-8" session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>page2</title>
</head>

<body>
  <%  
          out.println("getRequestURI():"+request.getRequestURI()+"<br/>");  
          out.println("getRequestURL():"+request.getRequestURL()+"<br/>");  
          out.println("getServletPath():"+request.getServletPath()+"<br/>");  
  %> 
</body></html>地址栏显示page1.jsp;如何获取到这个“page1.jsp”的字母串

解决方案 »

  1.   

    可以写一个方法。
    public String getFullURL(HttpServletRequest request) {
    StringBuffer url = request.getRequestURL();
    if (request.getQueryString() != null) {
    url.append('?');
    url.append(request.getQueryString());
    }
    return url.toString();
    }
      

  2.   

    js中直接可以location.href获得。
      

  3.   

    <%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    index
    </title>
    </head>
    <body bgcolor="#ffffff">
    <%
    response.sendRedirect("跳转页面");
    %>
    </body>
    </html>
      

  4.   

    request.getQueryString()得到的是一个空字符串。
    另外我需要在page2.jsp中的java代码片段中使用“浏览器地址栏的URL”,所以不可能在java代码的执行过程中使用JavaScript。
      

  5.   

    request.getHeader("reffer");   
      

  6.   


    这个我在项目中使用过的。能够正常取出request的URL。你DEBUG一下找找原因吧。
      

  7.   

    request.getQueryString()得到的是URL中?号之后的字符(不包括hash字符);
    其实我提的问题的关键在于
    request.getRequestURL()和浏览器地址栏的的URL不匹配。浏览器地址栏显示http://localhost:8080/page1.jsp,
    request.getRequestURL()得到的却是"http://localhost:8080/page1.jsp"

      

  8.   

    request.getRequestURL()和浏览器地址栏的的URL不匹配。浏览器地址栏显示http://localhost:8080/page1.jsp,
    request.getRequestURL()得到的却是"http://localhost:8080/page2.jsp" 
      

  9.   

    request.getRequestURL()和浏览器地址栏的的URL不匹配。
    浏览器地址栏显示http://localhost:8080/page1.jsp,
    request.getRequestURL()得到的却是"http://localhost:8080/page2.jsp"