• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Newbie wrestles with scope and includes

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very helpful. Thanks always.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic