rachel 发表于 2003-03-31 17:59

有关getRealPath()的问题

请问为什么我每次执行getRealPath("/index.htm")或传入其他参数,我得到的返回值总是NULL :wink:

ii 发表于 2003-03-31 20:02

有关getRealPath()的问题

<%@ page contentType="text/html;charset=GBK" %>;
<%@ page session="true" import="java.util.*" %>;

<%
String strEnvs[][] =
      {
                 {"CONTENT_LENGTH",String.valueOf(request.getContentLength())},
            {"CONTENT_TYPE",request.getContentType()},
            {"SERVER_PROTOCOL",request.getProtocol()},
          //{"SERVER_SOFTWARE",getServletContext().getServerInfo()},
                        {"SERVER_SOFTWARE",application.getServerInfo()},
                        {"SERVER_CLASSPATH",System.getProperty( "java.class.path" )},
                        {"REMOTE_ADDR",request.getRemoteAddr()},
            {"REMOTE_HOST",request.getRemoteHost()},
            {"REMOTE_USER",request.getRemoteUser()},
                        {"SERVER_NAME",request.getServerName()},
            {"SERVER_PORT",String.valueOf(request.getServerPort())},
            {"AUTH_TYPE",request.getAuthType()},
            {"REQUEST_METHOD",request.getMethod()},
            {"PATH_INFO",request.getPathInfo()},
            {"PATH_TRANSLATED",request.getPathTranslated()},
            {"QUERY_STRING",request.getQueryString()},
            {"REQUEST_URI",request.getRequestURI()},
                        {"SCRIPT_NAME",request.getServletPath()},
      //    {"DOCUMENT_ROOT",getServletContext().getRealPath("/")}
                        {"DOCUMENT_ROOT",application.getRealPath("/")}
      };
Enumeration enumNames;
String strName,strValue;
int i;
%>;

<html>;
<head>;

<title>;JSP例程 - 获取各种CGI环境变量</title>;
</head>;
<body>;<FONT face="verdana" SIZE="2" >;<CENTER>;JSP例程 - 获取各种CGI环境变量</CENTER>;
<table border=2 cellspacing=0 cellpadding=0 align=center>;
<tr>;
<th>;<FONT face="verdana" SIZE="2" >;Name</th>;
<th>;<FONT face="verdana" SIZE="2" >;Value</th>;
</tr>;
<%
        enumNames = request.getHeaderNames();
        while(enumNames.hasMoreElements()){
    strName = (String)enumNames.nextElement();
    strValue = request.getHeader(strName);
%>;
<tr>;
<td>;&amp;nbsp;<FONT face="verdana" SIZE="2" >;<%=strName%>;</td>;
<td>;&amp;nbsp;<FONT face="verdana" SIZE="2" >;<%=strValue%>;</td>;
</tr>;
<%
        }
%>;
<tr>;
<th>;<FONT face="verdana" SIZE="2" >;Name</th>;
<th>;<FONT face="verdana" SIZE="2" >;Value</th>;
</tr>;
<%
        for(i=0;i<strEnvs.length;i++){
%>;
<tr>;
<td>;&amp;nbsp;<FONT face="verdana" SIZE="2" >;<%=strEnvs%>;</td>;
<td>;&amp;nbsp;<FONT face="verdana" SIZE="2" >;<%=strEnvs%>;</td>;
</tr>;
<%
        }
%>;
</font>;</font>;</table>;
</body>;
</html>;

musicool 发表于 2003-04-02 20:45

有关getRealPath()的问题

HttpServletRequest和ServletContext中只有getRealPath(String path)方法

abc3214 发表于 2012-08-24 21:17

我得到的返回值也总是NULL啊

renxiao2003 发表于 2012-08-24 22:06

D:\apache-tomcat-6.0.26\webapps\tomcattest\index.jsp

我的能得到。
页: [1]
查看完整版本: 有关getRealPath()的问题