【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"); %>







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值