Dict.CN 在線詞典, 英語學習, 在線翻譯

          都市淘沙者

          荔枝FM Everyone can be host

          統計

          留言簿(23)

          積分與排名

          優秀學習網站

          友情連接

          閱讀排行榜

          評論排行榜

          JSP中與路徑相關的常用的幾個方法

          http:/localhost/123/jsp/test.jsp:

          <%@ page language="java" pageEncoding="UTF-8"%>

           

          <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

          <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

          <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

          <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

           

           

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

          <html:html lang="true">

            <head>

              <html:base />

             

              <title>test.jsp</title>

           

              <meta http-equiv="pragma" content="no-cache">

              <meta http-equiv="cache-control" content="no-cache">

              <meta http-equiv="expires" content="0">   

              <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

              <meta http-equiv="description" content="This is my page">

              <!--

              <link rel="stylesheet" type="text/css" href="styles.css">

              -->

           

            </head>

           

            <body>

          <p>

              <h2>application - javax.servlet.ServletContext</h2>

              application.getRealPath("/")<%=application.getRealPath("/") %><br>

              application.getMajorVersion() - <%=application.getMajorVersion() %><br>

              application.getMimeType("txt") - <%=application.getMimeType("txt") %><br>

              application.getServerInfo() - <%=application.getServerInfo() %><br>

              application.getServletContextName() - <%=application.getServletContextName() %><br>

              application.getContext()

          </p>

           

          <p>

              <h2>config - javax.servlet.ServletConfig</h2>

              config.getServletName() - <%=config.getServletName() %><br>

              config.getServletContext()<br>

          </p>

           

          <p>

              <h2>pageContext - javax.servlet.jsp.PageContext</h2>

              pageContext.getRequest()JSP中的requset隱式對象)<br>

              pageContext.getResponse()JSP中的response隱式對象)<br>

              pageContext.getServletConfig()JSP中的config隱式對象)<br>

              pageContext.getServletContext()JSP中的application隱式對象)<br>

              pageContext.getException()JSP中的exception隱式對象)<br>

              pageContext.getSession()JSP中的session隱式對象)<br>

              pageContext.getOut()JSP中的out隱式對象)

          </p>

           

          <p>

              <h2>request - javax.servlet.http.HttpServletRequest</h2>

              request.getLocalAddr() - <%=request.getLocalAddr() %><br>

              request.getServletPath() - <%=request.getServletPath() %><br>

              request.getContextPath() - <%=request.getContextPath() %><br>

              request.getLocalName() - <%=request.getLocalName() %><br>

              request.getLocalPort() - <%=request.getLocalPort() %><br>

              request.getPathInfo() - <%=request.getPathInfo() %><br>

              request.getProtocol() - <%=request.getProtocol() %><br>

              request.getQueryString() - <%=request.getQueryString() %><br>

              request.getRemoteAddr() - <%=request.getRemoteAddr() %><br>

              request.getRemoteHost() - <%=request.getRemoteHost() %><br>

              request.getRemotePort() - <%=request.getRemotePort() %><br>

              request.getRemoteUser() - <%=request.getRemoteUser() %><br>

              request.getRequestedSessionId():<%=request.getRequestedSessionId() %><br>

              request.getRequestURI() - <%=request.getRequestURI() %><br>

              request.getRequestURL() - <%=request.getRequestURL() %>

          </p>

           

          <p>

              <h2>session - javax.servlet.http.HttpSession</h2>

              session.getServletContext()

          </p>

           

            </body>

          </html:html>

          客戶端顯示如下:

          application - javax.servlet.ServletContext

          application.getRealPath("/")F:\workspace\tomcat\123\
          application.getMajorVersion() - 2
          application.getMimeType("txt") - null
          application.getServerInfo() - Apache Tomcat/5.0.30
          application.getServletContextName() - null
          application.getContext()

          config - javax.servlet.ServletConfig

          config.getServletName() - jsp
          config.getServletContext()

          pageContext - javax.servlet.jsp.PageContext

          pageContext.getRequest()
          pageContext.getResponse()
          pageContext.getServletConfig()
          pageContext.getServletContext()
          pageContext.getException()
          pageContext.getSession()
          pageContext.getOut()

          request - javax.servlet.http.HttpServletRequest

          request.getLocalAddr() - 127.0.0.1
          request.getServletPath() - /jsp/test.jsp
          request.getContextPath() - /123
          request.getLocalName() - 127.0.0.1
          request.getLocalPort() - 80
          request.getPathInfo() - null
          request.getProtocol() - HTTP/1.1
          request.getQueryString() - null
          request.getRemoteAddr() - 127.0.0.1
          request.getRemoteHost() - 127.0.0.1
          request.getRemotePort() - 1211
          request.getRemoteUser() - null
          request.getRequestedSessionId():5AFAE9C0A164621D4F8E0DAF2F253C92
          request.getRequestURI() - /123/jsp/test.jsp
          request.getRequestURL() - http://localhost/123/jsp/test.jsp

          session - javax.servlet.http.HttpSession

          session.getServletContext()

          注:

          http://localhost/123/taglib/html/result.jsp中使用以下方法

          request.getServletPath() :返回request的請求路徑的相對于應用程序的相對路徑

          request.getContextPath()返回應用程序上下文相對路徑

          this.getRealPath(String str)返回UILstr對應于本地磁盤的絕對路徑

          request.getLocalAddr() 返回服務器IP地址

          posted on 2007-12-01 12:58 都市淘沙者 閱讀(924) 評論(0)  編輯  收藏 所屬分類: Java Basic/Lucene/開源資料

          主站蜘蛛池模板: 准格尔旗| 灵寿县| 雅江县| 确山县| 米易县| 嘉禾县| 绥棱县| 贵州省| 蚌埠市| 灵川县| 游戏| 当涂县| 黑山县| 徐水县| 永嘉县| 龙陵县| 海伦市| 上杭县| 措美县| 凌源市| 土默特左旗| 博湖县| 呼图壁县| 西乌珠穆沁旗| 永康市| 平山县| 碌曲县| 通江县| 友谊县| 玛纳斯县| 和田市| 盈江县| 濉溪县| 崇信县| 泉州市| 南川市| 高碑店市| 饶平县| 武强县| 青冈县| 西华县|