my dog learned polymorphism
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
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: 33130

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

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] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: how to use global variable in JSP (scriptless)
It's not a secret anymore!