Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:08:31+00:00 2026-06-07T22:08:31+00:00

I have run into a wall trying to find an answer to this question

  • 0

I have run into a wall trying to find an answer to this question on how to avoid generating HTML within a custom tag handler. Like this questioner, I’m trying to avoid a bunch of println() statements in my tag handler, and I’d really like to pull in the data from another .jsp file.

Accordingly, I tried the method suggested:

public int doStartTag() throws JspException {
    try {
        pageContext.getResponse().flushBuffer();
        pageContext.getRequest()
                .getRequestDispatcher("/views/tags/loginBlock.jsp")
                .include(pageContext.getRequest(), pageContext.getResponse());
    } catch (Exception e) { throw new RuntimeException(e); }

    return EVAL_BODY_INCLUDE;
}

What I’m getting, however, is the content of loginBlock.jsp above the output of the jsp in which the tag is located, not inserted in place of the tag like I expected, even with the call to flushBuffer().

I have a questions that I’m trying to get answers to, but the gods of Google aren’t kind to me tonight:

  1. If I need to insert a block of HTML from a tag handler, is this the best way to do it?
  2. In the original answer, the poster uses a classic tag handler. Is there some way to do it using simple tag handler (that is, in a class that extends SimpleTagSupport) instead?
  3. Even though the questioner in the question liked above accepted an answer, I’m not able to duplicate successful results. Am I missing something that the questioner picked up on that I’m leaving out?
  4. Am I just way off base here in some way I’m not even aware of? I’m kind of new to the whole jsp/servlets thing, and I’m not 100% sure this design pattern is what I should be using. I’m basically trying to design jsp files that call back-end Java that performs some business logic and generates resultant HTML, but like I said above, I don’t want to stick a bunch of println() calls in my Java tag handlers.

Thanks for any help and/or insight!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:08:33+00:00Added an answer on June 7, 2026 at 10:08 pm

    Woot, I finally found a better answer, and I knew I had to be overlooking something probably relatively simple and fairly obvious. There’s another version of include() that takes a boolean as a second parameter. According to the documentation:

    If flush is true, The current JspWriter “out” for this JSP is flushed as a side-effect of this call, prior to processing the include. Otherwise, the JspWriter “out” is not flushed.

    So my original code above should be in a class that extends SimpleTagHandler, and should be this instead:

    public void doTag() {
        PageContext context = (PageContext)getJspContext();
        try {
            // The second parameter below (true) causes the JspWriter to be flushed
            context.include("/views/tags/loginBlock.jsp", true);
        } catch (Exception e) { throw new RuntimeException(e); }
    }
    

    Not only is that much shorter and simpler, but it means that I don’t have to go putting buffer=”none” in all of my JSP page directives. If anyone else runs across this question and answer, I hope you find it useful, because it sure caused me a bunch of grief. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've run into a wall trying to crack why this WordPress install hogs
I have run into a problem trying to modify a form I myself have
I have run into a problem... I'm trying to use QTKit in an application
I have been using handlebars.js for javascript view but have run into a wall
I seem to have run into to a wall that I can't get passed.
I'm learning C# coming from C++ and have run into a wall. I have
I have run into a brick wall with a Windows Service I wrote. The
I'm pretty new to javascript and programming and have run into a brick wall
I have a very odd issue trying to run this quite simple C program
I have run into a problem I have beat my head against the wall.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.