Question

I am new to working with jsp tags. I have a tag defined, and within the java class that is used to generate the tag, I would like to include a jsp file (the content is too long to be nicely maintainable as a java string). The problem is that tags do not get parsed and instead get outputted as is in the file returned to the browser.

An example of what I'm trying to do:

public class myTag extends TagSupport {

    @Override
    public int doStartTag() throws JspException {
        StringBuffer outString = new StringBuffer( "" );
        outString.append( "<table><tr><td>");

        outString.append("<jsp:include file=\"/widgets/myFile.jsp\" />");
        outString.append( "</td></tr></table>");
        try {
        pageContext.getOut().print( outString );
    } catch( IOException exception ) {
        throw new JspException( "ContactViewerTag: " + exception );
    }

        return EVAL_BODY_INCLUDE;
    }
}

Keep in mind that this is a very stripped down version of what I'm actually working with. If it was that simple, I would simply call the include from my main jsp file.

Is there any way to have an external jsp file be called and parse through a java class? If not, would anyone have any suggestions as to how I should go about doing this?

Était-ce utile?

La solution

Could you use:

PageContext.include

using your:

TagSupport.pageContext

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top