Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

%@include file= % ?  RSS feed

 
Andrew Mcmurray
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
 
Stefan Evans
Bartender
Posts: 1836
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
 
Balazs Borbely
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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 Redhat VI Editor
  • 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 Redhat VI Editor
  • 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
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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 Redhat VI Editor
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!