• Post Reply Bookmark Topic Watch Topic
  • New Topic

variables in a jsp:include?

 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
b youngblood
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ]
 
Peter Kleczka
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!