• 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

variables in a jsp:include?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to use some conditional logic to determine which HTML pages to include in a jsp file. I have tried a couple of variations and searched through some books and online resources and have not found a suitable way to do this.
My jsp provides data that needs to use a specific HTML header and footer out of a choice of about 20 different files.
If there is a way I can do this with includes or some other method I would really appreciate a suggestion.
Thanks,
Pat
 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved my problem and thought I'd post it here in case anyone else runs into this. It seems a little weird that it wouldn't work the way I was doing it the first time, but it does now :-)
At first I was trying to use includes like this:
<jsp:include page="/includes/<%= memberID %>/header.html" flush="true" />
and it would not work. I decided to try putting the entire URL together in a String first, and then write my include like this:
<jsp:include page="<%= memberIDHeader %>" flush="true" />
and now it works! I don't quite understand why it didn't work the first way but I'm happy now anyways :-)
Pat
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
trying to solve this very problem except my include file is a jsp and it says "Undefined variable or class name" on the included file. So it doesnt seem to be using the parent pages code.
[ July 07, 2003: Message edited by: b youngblood ]
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pat said


At first I was trying to use includes like this:

<jsp:include page="/includes/<%= memberID %>/header.html" flush="true" />

and it would not work. I decided to try putting the entire URL together in a String first, and then write my include like this:

<jsp:include page="<%= memberIDHeader %>" flush="true" />

and now it works! I don't quite understand why



I'm also trying to figure this out. Can someone explain?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a scriptlet expression is used as an attribute, it must be the entire attribute or none at all.

Another way of looking at it: an attribute can be a hard-coded value or a scriptlet expression, but not a mish-mash of the two.

Are you using JSP 2.0? There are better ways to accomplish this if so.
[ July 06, 2005: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic