File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need a little beginner Tag help

 
Ronnie Phelps
Ranch Hand
Posts: 329
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to define a String Object sT in a declaration tag as in:
<%! String st = "">
Then I want to assign this string a value within some scriptlet tags such as:
<% st = "filename.html %>
finally I want to include that string within an include tag as in:
<%@ include file=st %>
But I keep getting messages saying that st isn't defined...this is because the include tag is called before I define and assign a value to st. How can I enforce the scriptlet and declarative tags to be called before the include tag? Do I have to include another JSP?
 
Cameron Park
Ranch Hand
Posts: 371
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
include directive is pre-compiled so everything is already pre-set. Your code looks right to me except in the scriplet
<% st = "filename.html %>
Maybe it will work if it's corrected
<% st = "filename.html" %>
That case, if the include directive is placed after the above scriplet, it will be
<%@ include file = "filename.html"%>
 
Cameron Park
Ranch Hand
Posts: 371
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
include directive is pre-compiled so everything is already pre-set. Your code looks right to me except in the scriplet
<% st = "filename.html %>
Maybe it will work if it's corrected
<% st = "filename.html" %>
That case, if the include directive is placed after the above scriplet, it will be
<%@ include file = "filename.html"%>
Hope this helps.
 
Adam Chace
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure this isn't possible with the import statement, since it doesn't support a runtime expression value for the file attribute.
------------------
Adam Chace
Author of :JSP Tag Libraries
Chalk Creek Software
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways to include another page in a JSP. Using the directive as in :
< %@ include file="foo.jsp" %>
A directive cannot take a runtime expression. One advantage this has is the include happens at compile time and has the best overall performance.
The second is to use the jsp tag include. This is included at run time. I ran a quick test on Tomcat 3.2.1 and it does allow a runtime expression
< % String s = "foo.jsp"; %>
< jsp:include page="<%= s %>" flush="true"/>

------------------
Hope This Helps
Carl Trusiak, SCJP2
 
Ronnie Phelps
Ranch Hand
Posts: 329
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My fault. The scriptlet tag has a typo...but that's not my problem. So what are my options? Is this impossible?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic