Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

%@include file= % ?

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can <%@include file= take an expression as the value. For example



I can't seem to get it to work?

Thanks,

AMD
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>Can <%@include file= take an expression as the value?

no.
http://java.sun.com/products/jsp/syntax/1.2/syntaxref129.html#997991

but jsp:include can:
http://java.sun.com/products/jsp/syntax/1.2/syntaxref1214.html#8828

Basically the include directive gets evaluated at translation/compile time. As it is evaluated before the page is run, then it can't take runtime expressions.
The include directive is like copy/pasting a bunch of text into your JSP and then translating it into java and running it.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan

So will jsp:include work if the jsp file to include is just a jsp snippet not a whole jsp?

Thanks,
AMD
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give a look at 'tiles'.

UI design with Tiles and Struts
[ December 28, 2005: Message edited by: Balazs Borbely ]
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Balazas,

I am using tiles already. Basically I have a main content jsp and in that jsp there can be different fields dispalyed based on a request param that is coming in. So I get an id from a bean and based on what that id is add in a certain jsp snippet containing the additional fields that needs to be displayed based on that id.

Thanks,

AMD
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's wrong with using the include action?
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

The include directive does can not take expressions.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I said nothing about the include directive.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the include action? Does that work like the include directive, but takes expressions?
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Andrew Mcmurray:
Whats the include action?



Did you not read Stefan's reply?
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the <%@include file can not take expressions, but the jsp:include can I was wondering if you use jsp:include can the file your included be just a jsp snippet?

Thanks,

AMD
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah after reading Ben's link it looks like the the jsp in the include action needs to be able to run by itself. So that would mean not just a snippet right?

Thanks,

AMD
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right. The include action actually runs the included page as a separate JSP and merges the output at run-time.
[ December 29, 2005: Message edited by: Ben Souther ]
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Then this also means that the fields that I am getting from the include action will not be able to be submited with the parent jsp's form right?

Thanks,

AMD
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Andrew Mcmurray:
Hi Ben,

Then this also means that the fields that I am getting from the include action will not be able to be submited with the parent jsp's form right?

Thanks,

AMD



Yes, treat them as separate pages.
Bind the variables to request scope if you need them to be available to both JSPs.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Andrew Mcmurray:

Then this also means that the fields that I am getting from the include action will not be able to be submited with the parent jsp's form right?



It does not mean that. The included elements become part of the single HTML page sent to the browser. Whether the fragments were generated by the main JSP, an included fragment, a custom tag, or any other server-side action is moot.

Why not just try it and see what gets sent to the browser?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "fields" do you mean JSP (server-side) variables or HTML (client-side) form elements?
 
His brain is the size of a cherry pit! About the size of this ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic