jsp application内置对象深入理解与应用

// javax.servlet.jsp.PageContext:

public abstract ServletContext getServletContext();// application = pageContext.getServletContext();

// web容器实现了此抽象方法! 凡是接口或类中的抽象方法直接使用,都是因为容器或JVM内部实现了抽象!
// 此方法表示获取当前页面会话的服务器应用程序对象,也就是application,通过他可以设置和获取服务器的属性!
    The ServletContext instance.
// javax.servlet.ServeletContext:

public interface ServletContext;// 每个servletContext对象代表一个服务器应用程序,application是一个对象!

Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.
There is one context per “web application” per Java Virtual Machine. (A “web application” is a collection of servlets and content installed under a specific subset of the server’s URL namespace such as /catalog and possibly installed via a .war file.)
// 方法:

ServletContext getContext(String uripath);// 获取指定定位目录的服务器上下文对象,

Returns a ServletContext object that corresponds to a specifi

String getRealPath(String path);// 获取虚拟目录的真实路径

Returns a String containing the real path for a given virtual path. For example, the path “/index.html” returns the absolute file path on the server’s filesystem would be served by a request for “https://host/contextPath/index.html”, where contextPath is the context path of this ServletContext..
—获取虚拟目录的在服务器上的真实目录

<%@page contentType="text/html;utf8" import="java.io.*"%>

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

// 以上代码等价于以下代码:

<%@page contentType="text/html;utf8" import="java.io.*"%>

<%=this.getServletContext().getRealPath("/")%>

————application内置对象:
// javax.servlet.jsp.PageContext:

public abstract ServletContext getServletContext();// application = pageContext.getServletContext();

// web容器实现了此抽象方法! 凡是接口或类中的抽象方法直接使用,都是因为容器或JVM内部实现了抽象!
// 此方法表示获取当前页面会话的服务器应用程序对象,也就是application,通过他可以设置和获取服务器的属性!
    The ServletContext instance.
// javax.servlet.ServeletContext:

public interface ServletContext;// 每个servletContext对象代表一个服务器应用程序,application是一个对象!

Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.
There is one context per “web application” per Java Virtual Machine. (A “web application” is a collection of servlets and content installed under a specific subset of the server’s URL namespace such as /catalog and possibly installed via a .war file.)
// 方法:

ServletContext getContext(String uripath);// 获取指定定位目录的服务器上下文对象,

Returns a ServletContext object that corresponds to a specifi

String getRealPath(String path);// 获取虚拟目录的真实路径

Returns a String containing the real path for a given virtual path. For example, the path “/index.html” returns the absolute file path on the server’s filesystem would be served by a request for “https://host/contextPath/index.html”, where contextPath is the context path of this ServletContext..
—获取虚拟目录的在服务器上的真实目录

<%@page contentType="text/html;utf8" import="java.io.*"%>

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

// 以上代码等价于以下代码:

<%@page contentType="text/html;utf8" import="java.io.*"%>

<%=this.getServletContext().getRealPath("/")%>

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 嗅谱网
转载请注明:转自《jsp application内置对象深入理解与应用
本文地址:http://www.xiupu.net/archives-192.html
关注公众号:嗅谱网

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!