File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie wrestles with scope and includes

 
Bryan Timmins
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bryan Timmins
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very helpful. Thanks always.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic