• 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

request time attributes

 
Ranch Hand
Posts: 398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
People,
I have been going through Deshmukh's studykit and came across the following lines:

Using request Time attributes:
JSP expressions can be used to pass values to action attributes.
<% String pageURL = "copyRight.html" ; %>
< jsp:include file = "<%=pageURL %>" />
The expression here is not printed to the output stream but is evaluated at the request time and is passed to the page attribute of the include action.
An important point to note here is that such a mechanism of passing request time attributes is not valid in case of directives.
Thus,
<%! String bSize = "32kb";
String pageURL = "copyRight.html"
%>

<%@ page buffer = "<%=bSize %>" />
<%@ inlcude file = "<=pageURL %>" %> are not valid.

Now,
1. I understand that I can't use an expression as a value to an attribute of a directive. But why is the second line ( passing the same expression value to an action) not valid?
2. I tried both of the variations in my code and in both cases I am getting errors in compilation. The error I am getting is file pageURL not found.. What am I doing wrong?
Any inputs appreciated in advance.

Thanks,
vasu
[ November 14, 2002: Message edited by: vasu maj ]
 
Ranch Hand
Posts: 498
Eclipse IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the same chapter you read about <jsp:include> the book says that you cannot use runtime expressions for include directive because it is a translation time include.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please distinguish clearly between <%@ directives %> and <jsp: actions />! Directives are executed at compile time, when the JSP is compiled to Java code. Actions are executed at run time, when a browser request hits the JSP servlet.
To address your questions, 1) Both are directives; 2) I would expect the <jsp:include> to compile, but throw an exception at run time if pageURL does not exist; 3) <jsp:include> is not a directive, but an action; he is presumably talking about <%@include %> at that point.
- Peter
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%@ include ... %> is directive.
Whatever starts with <%@ is directive.
Directive means, it will be executed at translation time.
Translation Time: When jsp page is translated in to correcponding Servlet .java file.
Actions are runtime execution. When you say <jsp:include .. %> it is executed at runtime. So at that time value of variable is known.
Run time: When .class file of corresponding servlet is executed.
HTH
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Other than directive and actions explanations from above responses...here are some observations:
1. < jsp:include file = "<%=pageURL %>" />
Above should have been page= and not file=
2.
<%! String bSize = "32kb";
String pageURL = "copyRight.html"
%>
Missing ; on line 2
3. <%@ inlcude file = "<=pageURL %>" %>
Directive miss spelt, and expression should have been <%=
Didn't mean to be picky, but since you mention compilation issue I thought I'd share.
If code snippet provided is not correctly represented, ignore this reply.
Rama
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic