JSP including

R

Roedy Green

I am converting my own template engine over to Taglibs. One thing I
can do with my own engine is evaluate tags in included text at the
time the page including the text is expanded. The included tags get
evaluated in the context of the including page.

I am trying to find the equivalent feature in taglibs. I am getting
the impression that tags are all parsed ahead of time when the JSP is
converted to Java. Is there such a feature?

There seems to be a feature to include raw text at the last minute, or
tagged text at compile time.

If not, how do you deal with references in included boiler plate that
need to be made relative to the including page?

In particular I have a library of quotations, chock full of tag macros
(to handle things like birth/death dates, citations, relative
references to articles elsewhere on the website ...) then when
inserted in a page, should be expanded as if they have been in that
page all along.

I don't want to have to make up my mind which quotation to include
until the last second.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
E

EJP

I wouldn't be converting to anything that uses JSPs at this stage of the
game. I would look at anything built on JSF Facelets, e.g. JSF+RichFaces.
 
R

Roedy Green

I wouldn't be converting to anything that uses JSPs at this stage of the
game. I would look at anything built on JSF Facelets, e.g. JSF+RichFaces.

I read they were fifty times slower than JSP. Is that still true?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
C

ck

I am converting my own template engine over to Taglibs.  One thing I
can do with my own engine is evaluate tags in included text at the
time the page including the text is expanded.  The included tags get
evaluated in the context of the including page.

I am trying to find the equivalent feature in taglibs.  I am getting
the impression that tags are all parsed ahead of time when the JSP is
converted to Java. Is there such a feature?  

Tag libraries are Java classes(most of the time), so whatever you pass
to the tag, it would result in method invocation. Which implies it
would be parsed at the time of page load and not "ahead" of time.
You can confirm that by looking at the source of a compiled JSP that
invokes tag library.
 
M

markspace

Roedy said:
There seems to be a feature to include raw text at the last minute, or
tagged text at compile time.


<%@ include file="filename" %>
works at /translation/ time.


<jsp:include page="some.jsp" %>
works at /request/ time (runtime).


<c:import url="http://any.place.com/at/all" >
works at request time too, but takes URLs which is more flexible.


Source: Head First Servlets & JSP.
 
A

Arved Sandstrom

Roedy said:
I read they were fifty times slower than JSP. Is that still true?

If you're talking a JSP that isn't providing the view layer for JSF
(just as Facelets does), and is therefore fielding a request directly,
yes, I can't see how it wouldn't be faster, and probably considerably
faster when you clock it (although quite frankly I doubt a human being
would notice). However, as soon as you start adding in interesting
business logic the overhead of the JSF MVC framework is going to shrink
as a percentage, and in any case the advantages of JSF (with JSP or with
Facelets, either way) is going to then outweigh the disadvantages.

AHS
 
R

Roedy Green

Tag libraries are Java classes(most of the time), so whatever you pass
to the tag, it would result in method invocation. Which implies it
would be parsed at the time of page load and not "ahead" of time.
You can confirm that by looking at the source of a compiled JSP that
invokes tag library.

As I see it there are two times parsing could potentially happen.


1.the first time a *.jsp is accessed, it is parsed, converted to Java,
compiled and loaded.

2. every time a client accesses that page.


I referred to (1) as "ahead of time" since it is sooner that SSI would
parse, and sooner than (2).

The evaluation of the tag happens at (2), but the parsing/discovery of
tags, especially in included material, I suspect only happens at (1).
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
R

Roedy Green

<jsp:include page="some.jsp" %>
works at /request/ time (runtime).

Hmm. I don't think this is going to work. Every potential quotation
becomes a separate class, and it might not even know where it is
being included.

I am going to have to get rid of any tags in the quotations and make
them standard fields in a database.

Is there code you can put in your tag implementation code to generate
some raw text with included tags, then have that interpreted and
discarded?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
M

markspace

Roedy said:
Hmm. I don't think this is going to work. Every potential quotation
becomes a separate class, and it might not even know where it is
being included.

I am going to have to get rid of any tags in the quotations and make
them standard fields in a database.

Is there code you can put in your tag implementation code to generate
some raw text with included tags, then have that interpreted and
discarded?


I don't actually do JEE programming, so I don't have a full catalog of
implementations in my head. I have to look stuff up.

I think we are going to have to go back to basics and ask for a goal.
What is the goal? Spit random text out as a result of a call? Don't
ask for an implementation. I have no idea what "interpreted and
discarded" means anyway. What's the goal?
 
K

Kevin McMurtrie

Roedy Green said:
I am converting my own template engine over to Taglibs. One thing I
can do with my own engine is evaluate tags in included text at the
time the page including the text is expanded. The included tags get
evaluated in the context of the including page.

I am trying to find the equivalent feature in taglibs. I am getting
the impression that tags are all parsed ahead of time when the JSP is
converted to Java. Is there such a feature?

There seems to be a feature to include raw text at the last minute, or
tagged text at compile time.

If not, how do you deal with references in included boiler plate that
need to be made relative to the including page?

In particular I have a library of quotations, chock full of tag macros
(to handle things like birth/death dates, citations, relative
references to articles elsewhere on the website ...) then when
inserted in a page, should be expanded as if they have been in that
page all along.

I don't want to have to make up my mind which quotation to include
until the last second.

You can always view the intermediate Java source file produced by JSP
compilation. From what I've seen of Tomcat, tags turn into a sort of
interpreted language dispatched with Java calls. It's not fast but
filling in a template isn't too demanding.
 
A

Arne Vajhøj

Roedy said:
I read they were fifty times slower than JSP. Is that still true?

No.

Most JSF web apps uses JSP for view using JSF taglib.

A JSP with JSF tags is not 50 times slower than a JSP with XYZ tags.

The JSF servlet + the backing bean(s) + other code used is not 50
times slower than some homegrown code doing the same.

Arne
 
A

Arne Vajhøj

Roedy said:
Hmm. I don't think this is going to work. Every potential quotation
becomes a separate class, and it might not even know where it is
being included.

You asked for an include feature that evaluate tags at runtime.

This is it.

c:import is better but that is a minor detail.

You do not need to have a separate JSP per include - parameters
are allowed.
I am going to have to get rid of any tags in the quotations and make
them standard fields in a database.

Is there code you can put in your tag implementation code to generate
some raw text with included tags, then have that interpreted and
discarded?

That is what include and import does.

Arne
 
A

Arne Vajhøj

EJP said:
I wouldn't be converting to anything that uses JSPs at this stage of the
game. I would look at anything built on JSF Facelets, e.g. JSF+RichFaces.

JSP are still more popular than facelets as view technology for JSF.

In general I think JSF is a good choice for the typical Java web app.

But I am not sure that the complexity and the defined way of doing
things will fall in Roedys taste.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top