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的更多相关文章

  1. A brief introduction to per-cpu variables

    墙外通道:http://thinkiii.blogspot.com/2014/05/a-brief-introduction-to-per-cpu.html per-cpu variables are ...

  2. C# 7 out variables, tuples & other new features

    C# 7 out variables, tuples & other new features C# 7 is available on new Visual Studio 2017 and ...

  3. jsp 是什么 ,jsp 隐式对象

    google 搜索 java server page http://www.oracle.com/technetwork/java/javaee/jsp/index.html http://docs. ...

  4. A JSTL primer, Part 2: Getting down to the core

    In the initial article of this series, you got your first look at JSTL. We described the use of its  ...

  5. lambada 表达式

    1.lambada的存在来由 匿名类的一个问题是,如果匿名类的实现非常简单,例如只包含一个方法的接口,那么匿名类的语法可能看起来不实用且不清楚.在这些情况下,您通常会尝试将功能作为参数传递给另一个方法 ...

  6. Java Thread Local – How to use and code sample(转)

    转载自:https://veerasundar.com/blog/2010/11/java-thread-local-how-to-use-and-code-sample/ Thread Local ...

  7. 【翻译十一】java-原子性操作

    Atomic Access In programming, an atomic action is one that effectively happens all at once. An atomi ...

  8. Inversion of Control Containers and the Dependency Injection pattern(转)

    In the Java community there's been a rush of lightweight containers that help to assemble components ...

  9. How to Use JUnit With JMeter

    Do you need to use JUnit in your testing processes? To answer this question, let's take a look first ...

随机推荐

  1. linux上安装shell编辑器与linux运维面试题

    分两个部分 一.安装B-shell解释器 安装cygwin  Eclipse要找到安装的bin路径 https://cygwin.com 二.安装编辑器shellEd 下载可以得到一个:net.sou ...

  2. Java实现折半(二分)插入排序

    /*折半插入查找思想:每趟将一个带排序的元素作为关键字插入到已经排好的部分序列的适当位置上,查找适当位置的方法用折半查找法 * 适合记录数较多的场景 * 在查找插入位置时节省了时间 * 在记录移动次数 ...

  3. setValue 和 setObject 的区别

    在使用NSMutableDictionary 的时候经常会使用setValue forKey 与 setObject forKey,他们经常是可以交互使用的. 1.setValue forKey的定义 ...

  4. js 注册手机摇动事件

    var rockModule = (function () { //监听手机摇动事件 if (window.DeviceMotionEvent) { window.addEventListener(' ...

  5. C#扫盲之:带你掌握C#的扩展方法、以及探讨扩展方法的本质、注意事项

    1.为什么需要扩展方法 .NET3.5给我们提供了扩展方法的概念,它的功能是在不修改要添加类型的原有结构时,允许你为类或结构添加新方法. 思考:那么究竟为什么需要扩展方法呢,为什么不直接修改原有类型呢 ...

  6. magento 数据结构

    首先要知道是EAV模式,这种结构要比普通数据结构更容易扩展,但是带来的就是查询速度慢,好在magento的缓存机制不错 最重要的3张表eav_entity_type,eav_entity_attrib ...

  7. ScriptManager的用法

    资料中如实是说:       1, ScriptManager(脚本控制器)是asp.net ajax存在的基础. 2, 一个页面只允许有一个ScriptManager,并且放在其他ajax控件的前面 ...

  8. 20160417javaweb之servlet监听器

    监听器:监听器就是一个java程序,功能是监听另一个java对象变化(方法调用.属性变更) 8个监听器,分为了3种 写一个类实现响应的接口 注册监听器 -- 在web.xml中注册监听器 1.用来监听 ...

  9. 20160322 javaweb 学习笔记--response 重定向

    //一般方法 response.setStatus(302); response.setHeader("Location", "/20160314/index.jsp&q ...

  10. eclipse Ctrl+1 没反应

    今天上午写代码,突然发现Ctrl+1没反应了,顿时无语.昨天还好好的,今天就不行了…… 无奈,只好在网上查了查,据说快捷键冲突的原因比较大. 于是我将Ctrl+1换成了Alt+1.在eclipse中测 ...