在JSP程序片段中,包含如下隐含对象,每个对象都被固定的引用变量引用。JSP不需要做任何变量声明,就可以直接通过固定的引用变量来引用这些对象。
具体的类型取决于使用的协议类型,为javax.servlet.ServletRequest的子类,i.e.
javax.servlet.http.HttpServletRequest
Scope:request
具体的类型取决于使用的协议类型,为javax.servlet.ServletResponse的子类,i.e.
javax.servlet.http.HttpServletResponse
Scope:response
javax.servlet.jsp.PageContext
page context for this JSP page.
Scope:page
javax.servlet.ServletContext
servlet context obtained from the servlet configuration object(as in the call: getServletConfig().getContext() ).
Scope:application
javax.servlet.jsp.JspWriter
an object that writes into the output scream.
Scope:page
javax.servlet.ServletConfig
The ServletConfig for this JSP page.
Scope:page
java.lang.Object
The instance of this page's implementation class processing the current request.
page对象是this的同义词
Scope:page
javax.servlet.http.HttpSession
The session object created for the requesting client. This variable is only valid for HTTP protocols
Scope:session
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"); %>