tags:

views:

105

answers:

2

hi all i just want to create a simple jsp tag

such as :

abc.tag

<div>
    <table>
        ....
    </table>

    body content goes here

</div>


so when in the other pages i can use my tag like this
<tag:abc>
     acutally body content
</tag:abc>

how can i do it without java code??? coz the functionality for my tag is siimple, i don`t want to write a bunch of stuff for it

A: 

i have no idea what you're trying to do... but from what it looks like, i think you're trying to edit the font color of specified words? if so then you'd best be using CSS and perhaps JQuery. JQuery could be overkill though, so maybe just CSS

anonymous
jsp 2.0 tagscan allow people create a tag without writing any java code..for my case, i want to write a re-useable tag..imaging you always want to put some thing on top of your table.for createing a tag to do this,t u don`t need to always create that stuff for all your table, you just rewrite the table tag.
shrimpy
I kinda get you now, but i still think it would be more convenient to just use CSS. If i wanted to do something more complicated, i might consider this, however, for something as simple as colouring text, i'd just go with CSS as it's simpler. this is just my opinion but feel free to disregard it cause i'm not that experienced anyway haha
anonymous
+1  A: 

sigh

This is why JSP gets a bad wrap.

JSP 2.0 has a feature called "Tag Files". They let you create JSP tags using JSP.

What you want to do is trivial.

You will need to create a file named "abc.tag", and put it in, for example, WEB-INF/tags within your WAR.

The contents are simple for this case.

<div>
    <table>
        <jsp:doBody/>
    </table>
</div>

To use the file in your JSP:

sample.jsp:

<%@ taglib tagdir="/WEB-INF/tags" prefix="tag" %>
<tag:abc>
    actual body content
</tag:abc>

That's it! Shazam. The only caveat about tag files is that you can not use JSP scriptlets within you tag file tags. But, then, you shouldn't be do that anyway -- it's not a big deal.

Look up tag files for more details (like passing parameters and such).

Tag files, JSTL and EL make JSP 2.0 one of the best markup languages around.

Will Hartung
how about specify body-content="jsp"still cannot do scripte within the tag???
shrimpy