Good JSP custom tag tutorials

I

isamura

I have found a number of resources but have not been able to figure out how to emulate the
jsp:include tag behavior. In particular, the ability to resolve additional jsp tags defined within
the include page. For example,

<jsp:include page="mypage.htm" flush="true"> where mypage.htm might contain zero or more jsp tags.

Has anyone done this or can direct me to such a tutorial?

Thanks,

..K
 
A

Andrew Thompson

isamura said:
<jsp:include page="mypage.htm" flush="true"> where mypage.htm ..
Huh?

..might contain zero or more jsp tags.

Try renaming it to mypage.jsp, or better yet, mypage.f.jsp.
Since mypage should not contain an HTML or BODY element if
you want to include it in other pages. It should be a page
fragment, a 'snippet' of HTML or JSP/HTML.
 
I

isamura

...
: isamura wrote:
:
: > <jsp:include page="mypage.htm" flush="true"> where mypage.htm ..
:
: Huh?
:
: > ..might contain zero or more jsp tags.
:
: Try renaming it to mypage.jsp, or better yet, mypage.f.jsp.
: Since mypage should not contain an HTML or BODY element if
: you want to include it in other pages. It should be a page
: fragment, a 'snippet' of HTML or JSP/HTML.
:
I was not asking on how to use the jsp:include tag, but rather how to emulate its tag compiling
behavior in my custom tag. I should have specify the following instead:

<myjsp:myInclude page="mypage.htm" />

mypage.htm content:
<H2>how to get tags in here to resolve to HTML</H2>
<jsp:include page="test.htm" flush="true" />
<myjsp:customtag name="this" value="that" />
<P>Ideally any tags declared withing test.htm will get resolved too.
</P>

Any ideas?

..K
 
M

muthu.ramadoss

isam,

you would have to take the string and use the request/response objects
inside your tag implementation and dynamically invoke them on the page.
the jsp engine should take care of the rest.

the point is, use the existing mechansims to include the page instead
of trying to do it in your tag.

http://groups.google.com/group/EtoE
 
A

Andrew Thompson

isamura said:
...
: isamura wrote:
:
: > <jsp:include page="mypage.htm" flush="true"> where mypage.htm ..
:
: Huh?
:
: > ..might contain zero or more jsp tags.
:
: Try renaming it to mypage.jsp, ... ....
I was not asking on how to use the jsp:include tag, but rather how to emulate its tag compiling
behavior in my custom tag.

And that is what I was answering.
...I should have specify the following instead:

<myjsp:myInclude page="mypage.htm" />

No!

<myjsp:myInclude page="mypage.htm" />

...will not be 'compiled' because your server is being told (by you)
that it does not contain any compilable statements. If the name of
'mypage.htm' was instead 'mypage.jsp' - the Java container would
recognise it as a compilable piece of Java and treat it as such.

So, back to what I originally suggested..

Any ideas?

<wrily>
...try the advice offered by someone who uses JSP (successfully)
for all his sites.
</wrily>
 
I

isamura

...
: isamura wrote:
: > "Andrew Thompson" wrote ...
: > : isamura wrote:
: > :
: > : > <jsp:include page="mypage.htm" flush="true"> where mypage.htm ..
: > :
: > : Huh?
: > :
: > : > ..might contain zero or more jsp tags.
: > :
: > : Try renaming it to mypage.jsp, ...
: ...
: > I was not asking on how to use the jsp:include tag, but rather how to emulate its tag compiling
: > behavior in my custom tag.
:
: And that is what I was answering.
:
My mistake...

: >...I should have specify the following instead:
: >
: > <myjsp:myInclude page="mypage.htm" />
:
: No!
:
: <myjsp:myInclude page="mypage.htm" />
:
: ..will not be 'compiled' because your server is being told (by you)
: that it does not contain any compilable statements. If the name of
: 'mypage.htm' was instead 'mypage.jsp' - the Java container would
: recognise it as a compilable piece of Java and treat it as such.
:
: So, back to what I originally suggested..
:
: <myjsp:myInclude page="mypage.jsp" />
:
Actually I did try as you have suggested but the result was the same. Tags contained within
'mypage.jsp' did not get translated.

In my custom tag code, I use a BufferedReader to "include" mypage.jsp. Once the custom tag returns,
the outter page (index.jsp) is immediately sent to the browser. This leaves all "included" tags
unresolved.

The content that I am including is dynamic and needs to be resolved at runtime (on-demand), so the
container doesn't know if additional compiles are needed.

It seems as though I need to be able to compile the resulting output (perhaps repeatedly) before
sending the final output back to the browser. Perhaps there is a better solution...

: > Any ideas?
:
: <wrily>
: ..try the advice offered by someone who uses JSP (successfully)
: for all his sites.
: </wrily>
:
Perhaps you do have such a solution and would be willing to share it.

..K
 
A

Andrew Thompson

isamura said:
Perhaps you do have such a solution and would be willing to share it.

This is rather odd. I use JSP's and regurlarly use the include element
for fragments that are also .JSP (contain Java statements).

It works for me..

I'll think about it some more, but must admit that I am
stumped as to why it is not working for you. :-(
 
I

isamura

...
: isamura wrote:
:
: > Perhaps you do have such a solution and would be willing to share it.
:
: This is rather odd. I use JSP's and regurlarly use the include element
: for fragments that are also .JSP (contain Java statements).
:
By 'use' do you mean use of the standard jsp action tags such as jsp:include? If that is the case
then yes the included fragments will resolve even if it contains Java statements.

What I am doing is writing my own custom tags to add a slightly different behavior than the
jsp:include tag. However am finding that the included fragments do not resolve the same way.

Thanks for the suggestions though,

..K
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top