wood burning stoves 2.0
The moose likes JSP and the fly likes Newbie wrestles with scope and includes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Newbie wrestles with scope and includes" Watch "Newbie wrestles with scope and includes" New topic

Newbie wrestles with scope and includes

Bryan Timmins
Ranch Hand

Joined: Mar 26, 2001
Posts: 48
the problem that I can't seem to solve at the moment is passing a variable to includes that are dynamically compiled at runtime.
the main file is index.jsp
the example include is 03.jsp (one in a series of about 50 includes, all identified by number and all having the same template as this one).
the problem I'm having is at lines 97-120 in index.jsp. I'm testing to see if there are any more rows in the iteration because the last row is formatted differently than all the rows preceding it. so I assign a variable to that condition and then, I hoped, it would get passed on to the include. that is, I assumed that the include was in the same scope as the variable since they are in the same section of the loop.


TIA, On behalf of a JSP newbie.

<a href="http://www.bryantimmins.com" target="_blank" rel="nofollow">Bryan Timmins</a> <br />SCJP2
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Since you are using pageContext.include() to include the other jsp, isHighlight will not be visible. Remember, a JSP runs as a servlet and your scriptlets become code in the service() method of that servlet. That means that pageContext.include() is simply a method call to eventually executes another servlet (the one for 03.jsp) isHighlight is a local variable visible only in the enclosing if {} block in the index jsp-servlet.
What you will need to do is to put the isHighlight flag in one of the collections. Try using request.setAttribute() in index.jsp and then request.getAttribute() in the included jsp.
Also, I noticed that you use StringBuffer a lot but the way you use it doesn't buy you anything over using a String. Another thing: isHighlight == "yes" is wrong. Always use equals() method to test for String equality.

Junilu - [How to Ask Questions] [How to Answer Questions]
Bryan Timmins
Ranch Hand

Joined: Mar 26, 2001
Posts: 48
Very helpful. Thanks always.
I agree. Here's the link: http://aspose.com/file-tools
subject: Newbie wrestles with scope and includes
It's not a secret anymore!