JSP中怎么获取当前页面的绝对地址??

解决方案 »

  1.   

    public String getRealPath(String path)getRealPath("/");
      

  2.   

    说清楚点啊..我的程序如下:
    <%
      String tpath=request.getRequestURL();
      out.print("the path is:"+tpath);
    %>
    错误如下:org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 10 in the jsp file: /get_path.jsp
    Generated servlet error:
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\jsp\org\apache\jsp\get_005fpath_jsp.java:53: incompatible types
    found   : java.lang.StringBuffer
    required: java.lang.String
      String tpath=request.getRequestURL();
      

  3.   

    String tpath=request.getRequestURL().toString();
    不好意思,刚才忘了跟你说类型转换
      

  4.   

    以上只能获得服务器的地址:the path is:http://localhost:8080/jsp/get_path.jsp而不是磁盘的绝对地址...!!,这样上传的文件不是绝对地址..
      

  5.   

    <%
      String tpath=request.getRequestURL().toString();
      String tpath1=request.getRealPath("/");
      out.print("the path is:"+tpath);
      out.print("<br>the path is:"+tpath1);
    %>
    终于解结,这个可以的绝对地址的:tpath1=request.getRealPath("/");
      

  6.   

    java.lang.String 這個沒有引用