当前位置:Gxlcms > 数据库问题 > Accessing Scoped Variables

Accessing Scoped Variables

时间:2021-07-01 10:21:17 帮助过:2人阅读

To permit the JSP page to access the data, the servlet needs to use setAttribute to store the data in one of the standard locations: the HttpServletRequest, the HttpSession, or the ServletContext. Objects in these locations are known as “scoped variables,” and the expression language has a quick and easy way to access them.

You can also have scoped variables stored in the PageContext object, but this is much less useful because the servlet and the JSP page do not share PageContext objects. So, page-scoped variables apply only to objects stored earlier in the same JSP page, not to objects stored by a servlet. To output a scoped variable, you simply use its name in an expression language element.

For example, ${name} means to search the PageContext, HttpServletRequest, HttpSession, and ServletContext (in that order) for an attribute named. If the attribute is found, its toString method is called and that result is returned. If nothing is found, an empty string (not null or an error message) is returned.

So, for example, the following two expressions are equivalent. ${name} <%= pageContext.findAttribute("name") %>

 

http://pdf.coreservlets.com/JSP-EL.pdf

© Prentice Hall and Sun Microsystems Press. Personal use only

Accessing Scoped Variables

标签:

人气教程排行