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

  • Home
  • SEARCH
  • 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 6530653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:46:55+00:00 2026-05-25T09:46:55+00:00

Recently I’ve decided to get some knowledge about writing custom tags. And there is

  • 0

Recently I’ve decided to get some knowledge about writing custom tags. And there is a problem.

In my web app I use some JSTL tags and in every JSP page I have got an identical piece of code:

<c:if test="${sessionScope.locale == 'locale_ru_RU' or empty sessionScope.locale}" >
    <fmt:setBundle basename="locale_ru_RU" />
</c:if>
<c:if test="${sessionScope.locale == 'locale_en_US'}">
    <fmt:setBundle basename="locale_en_US" />
</c:if>

As you can see this construction sets correct resource bundle.

So I’d like to know if there is possibility to wrap up this piece of code and use instead of it a single tag (I know there is another way – just put this code in the individual JSP page and use <%@ include %> directive, but I’d like to try a tag)?

As I understand I should someway set body content (inside tag class, not from JSP) and make container to execute it, but I cannot find any examples about it.

What I have got now:

tld:

<?xml version="1.0" encoding="UTF-8"?>
<taglib   xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
 version="2.0">
<tlib-version>1.0</tlib-version>
<tag>
    <name>setLocale</name>
    <tag-class>com.test.tags.LocaleBundleTag</tag-class>
    <body-content>empty</body-content>
</tag>
</taglib>

and my tag:

public class LocaleBundleTag extends BodyTagSupport {

@Override
public void setBodyContent(BodyContent b) {

    try {
        b.clear();
        b.append("<c:if test=\"${sessionScope.locale == 'locale_ru_RU' or empty sessionScope.locale}\" >");
        b.append("<fmt:setBundle basename=\"locale_ru_RU\" />");
        b.append("</c:if>");
        b.append("<c:if test=\"${sessionScope.locale == 'locale_en_US'}\">");
        b.append("<fmt:setBundle basename=\"locale_en_US\" />");
        b.append("</c:if>");
    } catch (IOException e) {
    }

    super.setBodyContent(b);
}
}

It compiles, but does nothing correctly.

  • 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-25T09:46:55+00:00Added an answer on May 25, 2026 at 9:46 am

    No, that won’t work, because there’s no expectation that the body content will then also be processed by the JSP compiler. Rather you would need to implement the fmt:setBundle yourself within your tag.

    A JSP Tag file would be easier. Operationally it’s not that far removed from the include you mentioned, but it makes refactorings like this really trivial.

    I have an extended example here: JSP tricks to make templating easier?

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

Sidebar

Related Questions

Recently i am making an app on facebook. So i have use facebook api.
Recently, I'm trying to solve all the exercises in CLRS. but there are some
Recently, I started changing some of our applications to support MS SQL Server as
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently a friend and I were talking about securing stored procedure code in a
Recently I'm doing some work on RTMP streaming, that is using Flowplayer to integrate
Recently I've noticed that on occasion I do not get a mayorship notification when
Recently we have released our product. Our team decided to preserve the source code
Recently users of my website complained about the lack of support to IE6\7. Is
Recently I discovered a problem on the midas and I fixed it, the problem

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.