正文

JSP中与路径相关的常用的几个方法2007-04-09 11:28:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/hurongliang/24718.html

分享到:

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() - 2application.getMimeType("txt") - nullapplication.getServerInfo() - Apache Tomcat/5.0.30application.getServletContextName() - nullapplication.getContext() config - javax.servlet.ServletConfig config.getServletName() - jspconfig.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.1request.getServletPath() - /jsp/test.jsprequest.getContextPath() - /123request.getLocalName() - 127.0.0.1request.getLocalPort() - 80request.getPathInfo() - nullrequest.getProtocol() - HTTP/1.1request.getQueryString() - nullrequest.getRemoteAddr() - 127.0.0.1request.getRemoteHost() - 127.0.0.1request.getRemotePort() - 1211request.getRemoteUser() - nullrequest.getRequestedSessionId():5AFAE9C0A164621D4F8E0DAF2F253C92request.getRequestURI() - /123/jsp/test.jsprequest.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地址

阅读(9333) | 评论(4)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册