wood burning stoves 2.0*
The moose likes Servlets and the fly likes need a little beginner Tag help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "need a little beginner Tag help" Watch "need a little beginner Tag help" New topic
Author

need a little beginner Tag help

Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
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

Joined: Apr 06, 2001
Posts: 371
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

Joined: Apr 06, 2001
Posts: 371
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

Joined: May 24, 2001
Posts: 14
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


Adam Chace<BR>Author of :<A HREF="http://www.amazon.com/exec/obidos/ASIN/193011009X/electricporkchop/102-2552103-3190518" TARGET=_blank rel="nofollow">JSP Tag Libraries</A><BR><A HREF="http://www.chalkcreek.com" TARGET=_blank rel="nofollow">Chalk Creek Software</A>
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
My fault. The scriptlet tag has a typo...but that's not my problem. So what are my options? Is this impossible?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: need a little beginner Tag help