【Java.Web】JSP —— 语法基础 —— 隐式对象implicit Objects

隐含对象 - Implicit Objects

在JSP程序片段中,包含如下隐含对象,每个对象都被固定的引用变量引用。JSP不需要做任何变量声明,就可以直接通过固定的引用变量来引用这些对象。


request

具体的类型取决于使用的协议类型,为javax.servlet.ServletRequest的子类,i.e.

javax.servlet.http.HttpServletRequest

Scope:request

response

具体的类型取决于使用的协议类型,为javax.servlet.ServletResponse的子类,i.e.

javax.servlet.http.HttpServletResponse

Scope:response

pageContext

javax.servlet.jsp.PageContext

page context for this JSP page.

Scope:page

application

javax.servlet.ServletContext

servlet context obtained from the servlet configuration object(as in the call: getServletConfig().getContext() ).

Scope:application

out

javax.servlet.jsp.JspWriter

an object that writes into the output scream.

Scope:page

config

javax.servlet.ServletConfig

The ServletConfig for this JSP page.

Scope:page

page

java.lang.Object

The instance of this page's implementation class processing the current request.

page对象是this的同义词

Scope:page

session

javax.servlet.http.HttpSession

The session object created for the requesting client. This variable is only valid for HTTP protocols

Scope:session

exception

java.lang.Throwable

The uncaught Throwable that resulted in the error page being invoked.

Scope:page


示例

示例1:

<%
    String username = request.getParameter("username");
    out.print(username);
%>

<%
    String username = request.getParameter("username");
%>
<%= username %>

在上面的两段代码中,是等价的,都用于向页面打印username。


示例2:

再例如通过ServletContext隐含对象向Web应用范围内存放一个username属性,

<% application.setAttribute("username", "myName"); %>







你可能感兴趣的:(java,Web)