I need to have a string var declared in default.jsp page and the string var has to be accessible in the other jsp pages. Using the "public" modifier doesn't seem to work. //var declaration in default.jsp <% public String X=""; X += "<begin>"; %> //accessing in test1.jsp <% X += "test"; %> //accessing in test2.jsp <% X += "<end>"; %> Thanks.
where's my brain today? I also meant to mention that globals are a really bad idea in JSPs and Servlets - they tend to break the thread safety of the classes... Dave (again).
Roy Ben Ami
Ranch Hand
Joined: Jan 13, 2002
Posts: 732
posted
0
David, will the use of the declarative tag make the variable available to other JSP ??? i thought it just puts that variable outside the service method, thus making it an instance variable.....
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
posted
0
Roy, you are corect. It doesnot make it available to other JSP pages. It has to be added as an attribute to the session and have the other pages access the variable from the session. it can also be added to the request object and then forward that to the other pages.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Sean MacLean
author
Ranch Hand
Joined: Nov 07, 2000
Posts: 621
posted
0
Don't forget that you can use application scope as well, for a truely global 'variable'. Sean
Shubhrajit Chatterjee
Ranch Hand
Joined: Aug 23, 2001
Posts: 356
posted
0
And don't forget to make the setter methods of this object synchronized
Originally posted by Sean MacLean: Don't forget that you can use application scope as well, for a truely global 'variable'. Sean