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 7827331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:49:17+00:00 2026-06-02T09:49:17+00:00

I wonder how can I insert some JSP fragment into the BodyContent before it

  • 0

I wonder how can I insert some JSP fragment into the BodyContent before it is evaluated? I’ve tried different methods, none of them worked. I must be doing something wrong.

For example, I want someone to use my tag as:

<mytag:html>
   <mytag:head>
      <link href="test.css"></link>
   </mytag:head>

then it can insert a jsp fragment (read from config file) right after the head:

<link href="<%=request.getAttribute("theme")%>/test.css"/>

and it would finally output:

<html>
  <head>
    <link href="target-theme/test.css"></link>
    <link href="test.css"></link>
  </head>

Here is what I want to do:

  1. I want to simplify the JSP development of other team member by just using <myTag:*/>

  2. And I don’t want to hardcode some HTML output in MyTag.Java. That’s why I want to read some JSP fragment from an external file and inject it at runtime.

Any example/snippet for how to achieve this by using TagSupport?

  • 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-02T09:49:24+00:00Added an answer on June 2, 2026 at 9:49 am

    JSP files are transformed to servlets and at that point the invocation code for the JSP tags is also generated. Basically the servlet container instantiates your tags, sometimes using a pool of tag instances, but either way these instances are not directly exposed by the container.

    Inside the tag handlers there is no concept of JSP code. The tag handlers are “closer to the metal” (so to speak) and here you can only write directly to the response. You can’t evaluate JSP code. The body content is already evaluated at this point.

    So you can’t inject JSP fragments into your tag handlers, but you can have the tag handlers themselves pull content from that external file. But it would be static content!

    Things like <%=request.getAttribute("theme")%> will have no meaning here and will get sent directly to the client (as is). You could have some sort of JSP code in there if you limit yourself to EL expressions like ${theme} that you could evaluate yourself, but this will get very complicated very fast as your external code will get more complex.

    Depending on what you want to do, or what specification your servlet container implements, one other solution could be to use the JSP 2.0 tag files, so see if that could help given your situation (it would have been nice if JSPFragments could be built by the developer but unfortunately that’s container implementation).

    But what you are doing really sounds to me as decorating the output of other JSP code. If you want to simplify the development and add stuff later on top of its output, then also checkout SiteMesh. It is a web-page layout and decoration framework who can do what you are trying to achieve (and even more than that).

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

Sidebar

Related Questions

I'm trying to insert multiple times this same key into map but with different
SQL Question I wonder if I can write a single sql INSERT statement to
I wonder is anyone can help me with this annoying problem. Trying to insert
I want to insert multiple rows into different tables in my database. The statements
I have some SQL scripts for Oracle and I wonder to know exactly what
I wonder whether someone can help me please. I'm trying to implement the mysql_insert_id()
There was a previous question on StackOverflow about this subject (can insert the link,
I wonder how I can manipulate the DOM tree using PHP? I have seen
I am wondering how can I insert an element at the beginning of the
this question is uncategorized.. i guess. I wonder can i convert every recorded voice

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.