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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:03:53+00:00 2026-05-27T08:03:53+00:00

What are some ways (if any) to link or import a style sheet from

  • 0

What are some ways (if any) to link or import a style sheet from a JSP tag called in the <body>? It would be great if I can encapsulate all necessary imports in the JSP tag.

Current State

index.jsp:

<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="x" tagdir="/WEB-INF/tags" %>
<html>
    <head>
        <!-- we have to know what css file somecontent uses and include it here -->
        <!-- the tag below prints <link rel="/somecontent.css"... /> but makes sure this url is only included once -->
        <x:requireOnce loc="/somecontent.css" type="css" />
    </head>
    <body>
        <x:somecontent />
    </body>
</html>

Goal

index.jsp:

<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="x" tagdir="/WEB-INF/tags" %>
<html>
    <head>
        <%-- nothing for somecontent tag here --%>
    </head>
    <body>
        <x:somecontent />
        ...
    </body>
</html>

somecontent.tag:

<%@ tag description="some independent content" %>
<%@ taglib prefix="x" tagdir="/WEB-INF/tags" %>
<%-- the inline attribute will indicate that it is in the body and shouldn't use <link> which won't work here --%>
<x:requireOnce loc="/somecontent.css" type="css" inline="true" />
<%-- this will print <script type="text/javascript" src="/somecontent.js" ...></script> --%>
<x:requireOnce loc="/somecontent.js" type="js" />
...

Is there a way to keep a reference to the position in the head tag within the JspWriter and insert content there when necessary, i.e. new link tags?

Ideally, I don’t want to inline the contents of the stylesheet or use javascript to include the style sheet. Hopefully there’s some way with @import, <link> or some JSP magic… Thoughts?

  • 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-05-27T08:03:53+00:00Added an answer on May 27, 2026 at 8:03 am

    You could do something along the lines of what SiteMesh does.

    Each requireOnce tag would just put the file to link to in a list of files, stored in a request attribute. A servlet filter would buffer the whole response, and rewrite it when completed with the head section rewritten to include all the links.

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

Sidebar

Related Questions

I know there are some ways to get notified when the page body has
What are some ways that I can query the local machine's specifications (a range
Can you suggest some ways/tips to decrease Resharper memory usage in VS 2008. Working
Closed as duplicate of What are some ways to protect emails on websites from
Out of the various ways to import code, are there some ways that are
I've found some fairly long-winded ways to do this, but can't believe it's that
Some ways to iterate through the characters of a string in Java are: Using
What are some ways to write object-oriented code in C? Especially with regard to
i have found some ways but they are actually reading frames and applying transition
So the controller context depends on some asp.net internals. What are some ways to

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.