`
qxmcool
  • 浏览: 90864 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

jsp中获取路径

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

request.getLocalAddr() 返回服务器IP地址
分享到:
评论

相关推荐

    JSP中java脚本获取绝对路径

    JSP中java脚本获取绝对路径 。

    jsp获取文件夹路径

    获取文件夹路径,不是文件路径,但是这种方法需要设置安全等级,应为浏览器内核安全设置的时候是禁止范文文件夹路径的。

    JSP中得到几种得到路径的方法

    JSP中得到几种得到路径的方法,对此做出了总结。

    java中获取路径

    java、servlet、jsp、class等等中如何获得所在的路径

    jsp获取文件完整路径

    可以获取文件完整路径,不过要求环境是在windows下的google浏览器,应为不同浏览器,不同操作系统下获取文件路径方法不同,我没有找到通用的方法,因为浏览器处于安全考虑本身就禁止访问本地中的文件系统。

    jsp获取url路径的方法分析.docx

    jsp获取url路径的方法分析.docx

    Jsp选择路径.rar

    Jsp选择路径.rar Jsp选择路径.rar Jsp选择路径.rar Jsp选择路径.rar

    JAVA类,JSP,Servlet获取工程路径.txt

    JAVA类,JSP,Servlet获取工程路径.txt 总共罗列出了集中jsp servlet 在eclipse 里 获得项目工程路径的方法

    jsp中获取当前目录的方法

    本文实例讲述了jsp中获取当前目录的实现方法,分享给大家供大家参考。具体实现方法如下: 1、利用System.getProperty()函数获取当前路径: 代码如下:System.out.println(System.getProperty(“user.dir”));//user....

    JAVA获取各种路径总结

    JSP中获得当前应用的相对路径和绝对路径  根目录所对应的绝对路径、 文件的绝对路径 、 当前web应用的绝对路径、 取得请求文件的上层目录……

    JSP页面显示PDF,根据PDF路径在JSP页面显示PDF

    根据PDF的存放路径,将PDF文件显示在JSP页面,可显示多个,也可显示固定的一个 根据具体需求在JSP页面显示一个或者多个PDF

    jsp获取url路径的方法分析

    本文实例讲述了jsp获取url路径的方法。分享给大家供大家参考,具体如下: 如果你请求的URL是 http://localhost:8080/demo/Index.jsp request.getScheme() //输出:http request.getServerName() //输出: ...

    java获取路径的各种方法

    关于JSP/Servlet中的相对路径和绝对路径。2.1服务器端的地址服务器端的相对地址指的是相对于你的web应用的地址,这个地址是在服务器端解析的(不同于html和javascript中的相对地址,他们是由客户端浏览器解析的)

    jsp中获得路径的两种方法和获得url路径的方法(推荐)

    &lt;a&gt;/XXX.jsp”&gt; //这样获得的是绝对路径 &lt;a&gt; //这样获得的是相对路径 &lt;a&gt;/XXXX.jsp”&gt; 能够更有效的防治连接的失效。 request.getContextPath()得到的是项目的名字,如果项目为根目录,则得到一个””,即空的字条串...

    jquery_params.js获取页面路径后参数....

    [removed][removed] [removed][removed] account.jsp?name="+name+"&sex;="+sex; var name = $.query.get("name"); var sex = $.query.get("sex");

    Java,JSP,Servlet获取当前工程路径(绝对路径)问题解析

    主要介绍了Java,JSP,Servlet获取当前工程路径(绝对路径)问题解析,需要的朋友可以参考下。

    JSP实用技巧集合,jsp编程的一些小技巧总结

    包括JSP编程中常用的js技术。 1.JSP编程中常用的js技术 2. 在下拉列表框里选择一个值后跳出新窗口? 3. 在JSP中启动execl? 4. 两级下拉列表框联动菜单? 5. java中如何把一个目录下的文件移到另一个指定的目录? 6. ...

    J2ee中的路径问题(word文档)

    jsp和sevlet中的相对路径和绝对路径!以及获取路径的方法!jsp 和 servlet的路径对比!文档很简单实用 !

Global site tag (gtag.js) - Google Analytics