您的位置:首页 > Web前端 > JavaScript

[转]JSP中与路径相关的常用的几个方法

2010-10-01 10:19 465 查看
虽然很简单,但是很全,有时候很久没用好了还真是记不住,所以转载过来了。

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

1:

2:

3:

4:

5:

6:

7:

8:

9:  DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

10:  <html:html lang="true">

11:    <head>

12:      <html:base />

13:

14:      <title>test.jsptitle>

15:

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

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

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

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

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

21:

24:

25:    head>

26:

27:    <body>

28:  <p>

29:      <h2>application - javax.servlet.ServletContexth2>

30:      application.getRealPath("/")<br>

31:      application.getMajorVersion() - <br>

32:      application.getMimeType("txt") - <br>

33:      application.getServerInfo() - <br>

34:      application.getServletContextName() - <br>

35:      application.getContext()

36:  p>

37:

38:  <p>

39:      <h2>config - javax.servlet.ServletConfigh2>

40:      config.getServletName() - <br>

41:      config.getServletContext()<br>

42:  p>

43:

44:  <p>

45:      <h2>pageContext - javax.servlet.jsp.PageContexth2>

46:      pageContext.getRequest()(JSP中的requset隐式对象)<br>

47:      pageContext.getResponse()(JSP中的response隐式对象)<br>

48:      pageContext.getServletConfig()(JSP中的config隐式对象)<br>

49:      pageContext.getServletContext()(JSP中的application隐式对象)<br>

50:      pageContext.getException()(JSP中的exception隐式对象)<br>

51:      pageContext.getSession()(JSP中的session隐式对象)<br>

52:      pageContext.getOut()(JSP中的out隐式对象)

53:  p>

54:

55:  <p>

56:      <h2>request - javax.servlet.http.HttpServletRequesth2>

57:      request.getLocalAddr() - <br>

58:      request.getServletPath() - <br>

59:      request.getContextPath() - <br>

60:      request.getLocalName() - <br>

61:      request.getLocalPort() - <br>

62:      request.getPathInfo() - <br>

63:      request.getProtocol() - <br>

64:      request.getQueryString() - <br>

65:      request.getRemoteAddr() - <br>

66:      request.getRemoteHost() - <br>

67:      request.getRemotePort() - <br>

68:      request.getRemoteUser() - <br>

69:      request.getRequestedSessionId():<br>

70:      request.getRequestURI() - <br>

71:      request.getRequestURL() -

72:  p>

73:

74:  <p>

75:      <h2>session - javax.servlet.http.HttpSessionh2>

76:      session.getServletContext()

77:  p>

78:

79:    body>

80:  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)返回UIL中str对应于本地磁盘的绝对路径

request.getLocalAddr() 返回服务器IP地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: