scope order of initialization of variabes includes

2004-03-02 Thread Marc Hughes
I have the following situation:

Page1.jsp:

jsp:useBean id=bandbg scope=request class=java.lang.String /
%   bandbg = ok;   %
First page: %= bandbg %
jsp:include page=page2.jsp  /
Page2.jsp:
jsp:useBean id=bandbg scope=request class=java.lang.String /
BRSecond page: %= bandbg %
Viewing page1.jsp I get the output:
First page: ok
Second page:
I thought I should get the output:
First page: ok
Second page: ok
I've tried with application  session scope too.

I'm assuming I'm just misunderstanding how things work.  Maybe tomcat 
starts processing includes before it processes the page or something?  
Any comments?

Thanks
-Marc
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: scope order of initialization of variabes includes

2004-03-02 Thread Asim Alp
I think you need to remove jsp:useBean ... part from page2.

Asim

On Mar 2, 2004, at 12:09 PM, Marc Hughes wrote:

I have the following situation:

Page1.jsp:

jsp:useBean id=bandbg scope=request class=java.lang.String /
%   bandbg = ok;   %
First page: %= bandbg %
jsp:include page=page2.jsp  /
Page2.jsp:
jsp:useBean id=bandbg scope=request class=java.lang.String /
BRSecond page: %= bandbg %
Viewing page1.jsp I get the output:
First page: ok
Second page:
I thought I should get the output:
First page: ok
Second page: ok
I've tried with application  session scope too.

I'm assuming I'm just misunderstanding how things work.  Maybe tomcat 
starts processing includes before it processes the page or something?  
Any comments?

Thanks
-Marc
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: scope order of initialization of variabes includes

2004-03-02 Thread Christopher Schultz
Marc,

I thought I should get the output:
First page: ok
Second page: ok
I think this is what's happening. (You can probably verify this by 
looking at the java source code generated by Tomcat from your JSP):

When you do a jsp:useBean and declare where the bean lives, the 
translator essentially converts that to this line of code:

String bandBg = (String)request.getAttribute(bandBg);

Then, later, you are using a scriptlet to do this:

bandBg = ok;

In the other JSP, the same code executes:

String bandBg = (String)request.getAttribute(bandBg);

However, you never poked 'ok' back into the request, so it's still 
either null or blank or whatever it was when you started.

Setting the local reference bandBg in your Page1.jsp doesn't do anything 
outside of it. You'd have to do something like this in your scriptlet to 
make it work:

% request.setAttribute(bandBg, ok); %

If you're going to use jsp:useBean, you probably shouldn't screw 
around with those variables inside of scriptlets. Try to stick with the 
bean tags only. That generally means that you'll have to write your own 
bean instead of using a string (so it can have a 'setValue' method or 
something).

Hope that helps.

-chris


signature.asc
Description: OpenPGP digital signature


Re: scope order of initialization of variabes includes

2004-03-02 Thread Marc Hughes
Ah.. figured it out...
%  
 bandbg = ok;  
%

is like

%  
bandbg =  new String(ok);  
%

I wasn't setting a string, I was creating a new one... doh.

Thanks anyways!
-Marc
Marc Hughes wrote:

I have the following situation:

Page1.jsp:

jsp:useBean id=bandbg scope=request class=java.lang.String /
%   bandbg = ok;   %
First page: %= bandbg %
jsp:include page=page2.jsp  /
Page2.jsp:
jsp:useBean id=bandbg scope=request class=java.lang.String /
BRSecond page: %= bandbg %
Viewing page1.jsp I get the output:
First page: ok
Second page:
I thought I should get the output:
First page: ok
Second page: ok
I've tried with application  session scope too.

I'm assuming I'm just misunderstanding how things work.  Maybe tomcat 
starts processing includes before it processes the page or something?  
Any comments?

Thanks
-Marc
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]