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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:51:13+00:00 2026-05-11T14:51:13+00:00

When trying to use a custom JSP tag library, I have a variable defined

  • 0

When trying to use a custom JSP tag library, I have a variable defined in JSP that I would like to be evaluated before being passed to the tag library. However, I cannot seem to get it to work. Here’s a simplified version of my JSP:

<% int index = 8; %>  <foo:myTag myAttribute='something_<%= index %>'/> 

The doStartTag() method of my TagHandler uses the pageContext’s output stream to write based on the inputted attribute:

public int doStartTag() {     ...     out.println('Foo: ' + this.myAttribute); } 

However, the output I see in my final markup is:

Foo: something_<%= index %> 

instead of what I want:

Foo: something_8 

My tag library definition for the attribute is:

<attribute>     <name>myAttribute</name>     <required>true</required> </attribute> 

I have tried to configure the attribute with rtexprvalue both true and false, but neither worked. Is there a way I can configure the attribute so that it’s evaluated before being sent to the Handler? Or am I going about this totally wrong?

I’m relatively new to JSP tags, so I’m open to alternatives for solving this problem. Also, I realize that using scriptlets in JSP is frowned upon, but I’m working with some legacy code here so I’m kind of stuck with it for now.

Edit:

I have also tried:

<foo:myTag myAttribute='something_${index}'/> 

which does not work either – it just outputs something_${index}.

  • 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. 2026-05-11T14:51:13+00:00Added an answer on May 11, 2026 at 2:51 pm

    I don’t believe that you can use a <%= ... %> within an attribute in a custom tag, unless your <%= ... %> is the entire contents of the attribute value. Does the following work for you?

    <% int index = 8; %> <% String attribValue = 'something_' + index; %>  <foo:myTag myAttribute='<%= attribValue %>'/> 

    EDIT: I believe the <% ... %> within the custom tag attribute can only contain a variable name. not any Java expression.

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

Sidebar

Related Questions

I'm trying to use a custom configuration section, something I've done numerous times before
I'm trying to use multiple attributes in my custom tag, e.g.: <mytaglib:mytag firstname=Thadeus lastname=Jones
I'm trying to serialize a custom class that needs to use multiple elements of
I'm trying to use custom container widgets in gtk.Builder definition files. As far as
I'm building a custom web part for SharePoint and I'm trying to use the
While trying to use LINQ to SQL I encountered several problems. I have table
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
I' trying to use a Linq query to find and set the selected value
I trying to use ImageInfo and Jython to get information from a image on

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.