File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

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.


[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
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

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]
 
GeeCON Prague 2014
 
subject: how to use global variable in JSP (scriptless)