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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Newbie wrestles with scope and includes" Watch "Newbie wrestles with scope and includes" New topic
Author

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.
index.jsp:

03.jsp:

TIA, On behalf of a JSP newbie.

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

Joined: Feb 26, 2001
Posts: 4442
    
    5

Bryan,
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.
HTH,
Junilu

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
 
Similar Threads
Struts: Getting a blank page instead of the form
Connection Pooling
page refresh problem
Has anyone seen this error before??
jsp:include and c:import combination/nesting