Skip to main content

[webtier] Custom JSTL Tag. Include page from a tag

3 replies [Last post]
Anonymous

Hi everyone,

I have a custom tag who will include another JSP page. But when I use this
tag, the result page is always blank without any html tag and no exception.
I have tried to write a link instead of including the page and the link goes
to the page to include so my path is correct.
How can I include (and evaluate the included content) from a custom tag ?

Here is my "doStartTag" content. The full tag can be found as attachment.

> public int doStartTag() throws JspException {

try {

StringBuilder path = new StringBuilder()

.append("../../extended/").append(extended)

.append('/').append(part).append(".jsp");

pageContext.getOut().write("Page");

pageContext.include(path.toString(), true);

} catch (Exception e) {

e.printStackTrace();

}

return EVAL_BODY_AGAIN;

}

// doEndTag return "EVAL_PAGE"

Thanks

--
Gervais Blaise

[att1.html]
[ExtensionTag.java]
---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kchung
Offline
Joined: 2004-05-06
Points: 0

I simplified your test case further:

package test;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class TTag extends TagSupport {

@Override
public int doStartTag() throws JspException {

try {
pageContext.getOut().write("Including test.jsp ");
pageContext.include("test.jsp", true);
pageContext.getOut().write("After test.jsp ");
} catch (Exception e) {
throw new JspException(e);
}
return EVAL_BODY_AGAIN;
}
}

The include works as expected. No idea why it didn't work for you.

BTW, doStartTag should not return EVAL_BODY_AGAIN, it should return either SKIP_BODY or EVAL_BODY_INCLUDE.

Blaise Gervais

Thanks.

I was wondering if a tag can include a JSP but you said that it can so I'm
doing something wrong.
In fact, my "path" was wrong but I expected to receive an exception and not
an empty response.

2010/6/9

> I simplified your test case further:
>
> package test;
>
> import javax.servlet.jsp.JspException;
> import javax.servlet.jsp.tagext.TagSupport;
>
> public class TTag extends TagSupport {
>
> @Override
> public int doStartTag() throws JspException {
>
> try {
> pageContext.getOut().write("Including test.jsp ");
> pageContext.include("test.jsp", true);
> pageContext.getOut().write("After test.jsp ");
> } catch (Exception e) {
> throw new JspException(e);
> }
> return EVAL_BODY_AGAIN;
> }
> }
>
> The include works as expected. No idea why it didn't work for you.
>
> BTW, doStartTag should not return EVAL_BODY_AGAIN, it should return either
> SKIP_BODY or EVAL_BODY_INCLUDE.
> [Message sent by forum member 'kchung']
>
> http://forums.java.net/jive/thread.jspa?messageID=473452
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

--
Gervais Blaise

[att1.html]

kchung
Offline
Joined: 2004-05-06
Points: 0

Have you checked the server.log for any indications about the non-existent file? I'm the container would say something there.

I agree that it would be nice to get a message at the response.