Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Good JSP custom tag tutorials

Thread view: 
isamura - 26 Oct 2005 03:38 GMT
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
Andrew Thompson - 26 Oct 2005 04:28 GMT
> <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.
isamura - 26 Oct 2005 15:38 GMT
: > <jsp:include page="mypage.htm" flush="true"> where mypage.htm  ..
:
[quoted text clipped - 6 lines]
: 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
muthu.ramadoss@gmail.com - 26 Oct 2005 21:02 GMT
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
Andrew Thompson - 31 Oct 2005 02:50 GMT
> : > <jsp:include page="mypage.htm" flush="true"> where mypage.htm  ..
> :
[quoted text clipped - 3 lines]
> :
> : 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..

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

> Any ideas?

<wrily>
..try the advice offered by someone who uses JSP (successfully)
for all his sites.
</wrily>
isamura - 31 Oct 2005 18:37 GMT
"Andrew Thompson" wrote...

: > : > <jsp:include page="mypage.htm" flush="true"> where mypage.htm  ..
: > :
[quoted text clipped - 8 lines]
:
: And that is what I was answering.

My mistake...

: >...I should have specify the following instead:
: >
[quoted text clipped - 12 lines]
:
: <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
Andrew Thompson - 01 Nov 2005 04:37 GMT
> 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.  :-(
isamura - 01 Nov 2005 06:21 GMT
: > 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.