Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes JSP and the fly likes how to use global variable in JSP (scriptless) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to use global variable in JSP (scriptless)" Watch "how to use global variable in JSP (scriptless)" New topic

how to use global variable in JSP (scriptless)

jamil lusa
Ranch Hand

Joined: Aug 18, 2011
Posts: 59
hi all,

for the example below:

the EL above ${userName} refer to the attribute which is added in scope. how am i able to use global variable (member variable) in user=? for example the global variable like below:

how can we refer the global object scriptlessly?

thanks in advanced.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31668

There's no such thing as a global variable in EL. What you do is setAttribute() from the servlet (or other class) before calling the JSP. If you want it available on all JSP pages, you can put it in a filter that always gets called.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62294

Or, if the same value is to be used by all users, you can put a "global" variable in application scope.

What you moist certainly do not want to do is to mix the EL and JSTL with scriptlets. That's just a big ol' mess!

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jQuery in Action, 2nd edition
subject: how to use global variable in JSP (scriptless)