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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:01:11+00:00 2026-05-28T11:01:11+00:00

i wrote custom tag which makes it easy to localize strings; in jsp it

  • 0

i wrote custom tag which makes it easy to localize strings;

in jsp it looks like this:

 <ct:word key="${message}"/>

message passed from servlet.
This tag takes needed string from the ResourceBundle.
Everything works but there is a problem. If i didn’t pass message from servlet then my app throw Exception(ResourceBundle can not find the necessary string).
How to ensure that custom tag did not respond to null and skipped? like it does

<c:out />  

code im my custom tag:

private String key;
private String value;

public void setKey(String key) {
    this.key = key;
}

public String getKey() {
    return this.key;
}

public int doStartTag() {
    try {
        this.checkLocale();//check locale and init resourceBundle
        value = resourceBundle.getString(key);
        pageContext.getOut().write(value);
    } catch (IOException e) {
        logger.error(e);
    } catch (MyException e1) {
        logger.error(e1);
    }
    return SKIP_BODY;
}

I don’t want to use

<c:if test="${not empty message}"/> or <c:when/>

it’s clutters the code on jsp

UPDATED:
i try

    } catch (MyException e1) {
        logger.error(e1);
        return SKIP_BODY;
    }

but i have Exception:

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key 

in my methods i catch

    catch (MissingResourceException e) {
        throw new MyException(Constants.ERROR_TRANSLATE_TAG,e);
    }

my app issues this exception ONLY if i I did not pass this message from servlet. I want to display page even if i dont have this message, without error pages.

  • 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-28T11:01:11+00:00Added an answer on May 28, 2026 at 11:01 am

    For the record:

    resourceBundle.getString(key); will throw a MissingResourceException if the key cannot be found, thus catch that exception as well in the doStartTag() method.

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

Sidebar

Related Questions

I would like to write a custom JSP tag whose output includes other JSP
Is it possible to write a custom JSP tag to take an i18n message
I'm creating a Custom tag in my web.config. I first wrote the following entry
When trying to use a custom JSP tag library, I have a variable defined
I'm trying to write a Struts2 tag to my JSP from a custom tag.
I have a custom tag lib that I wrote so that I can display
I am trying to write a custom tag. I can write attributes; however, I'm
I wrote a custom web part for SharePoint 2007 that loads an existing user
I wrote a custom URL rewriting module, to take certain paths and map them
I wrote a custom WCF binding a while back to allow my load balanced

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.