• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request time attributes

 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • 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 ]
 
Marcelo Sousa Ancelmo
Ranch Hand
Posts: 498
Eclipse IDE Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • 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.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • 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
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • 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
 
Rama Raghavan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic