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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:01:42+00:00 2026-06-03T05:01:42+00:00

I am working on a Spring application and in JSPX page I need to

  • 0

I am working on a Spring application and in JSPX page I need to dynamically load some values from properties page and set them as dropdown using options tag. I need to use same text for options value and for displaying but for options value, I need to remove all special characters.

For example if value is Maternal Uncle, then I need

<option value="MaternalUncle">Maternal Uncle</option>

What I am getting is

<option value="Maternal Uncle">Maternal Uncle</option>

There are 2 applications which can use that page and which properties file to load depends on app. If I load values for app 1 then values get displayed properly, Last value in app1 is ‘Others’ and does not has any special characters. For app 2 it does not trims whitespaces where last value is ‘Maternal Uncle’. repOptions in code is ArrayList with values loaded from properties file. Here is my code:

<select name="person" id="person">
      <option value="na">Select the relationship</option>
  <c:forEach items="${repOptions}" var="repOption">
       <option value="${fn:replace(repOption, '[^A-Za-z]','')}">${repOption}</option>
  </c:forEach>
</select>

First app removes whitespaces as this value is 4th in list of 9. For app2 , this is last value and regex does not works. If I put Maternal Uncle as first property for app2 then this works fine but requirements is to have it last option.

 <option value="${fn:replace(repOption, ' ','')}">

is working for whitespaces but there can be values like Brother/Sister, so I need to remove / also, hence I am using regex.

  • 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-03T05:01:44+00:00Added an answer on June 3, 2026 at 5:01 am

    The JSTL fn:replace() does not use a regular expression based replacement. It’s just an exact charsequence-by-charsequence replacement, exactly like as String#replace() does.

    JSTL does not offer another EL function for that. You could just homegrow an EL function yourself which delegates to the regex based String#replaceAll().

    E.g.

    package com.example;
    
    public final class Functions {
    
         private Functions() {
             //
         }
    
         public static String replaceAll(String string, String pattern, String replacement) {
             return string.replaceAll(pattern, replacement);
         }
    
    }
    

    Which you register in a /WEB-INF/functions.tld file as follows:

    <?xml version="1.0" encoding="UTF-8" ?>
    <taglib 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
        version="2.1">
    
        <display-name>Custom Functions</display-name>    
        <tlib-version>1.0</tlib-version>
        <uri>http://example.com/functions</uri>
    
        <function>
            <name>replaceAll</name>
            <function-class>com.example.Functions</function-class>
            <function-signature>java.lang.String replaceAll(java.lang.String, java.lang.String, java.lang.String)</function-signature>
        </function>
    </taglib>
    

    And finally use as below:

    <%@taglib uri="http://example.com/functions" prefix="f" %>
    
    ...
    
    ${f:replaceAll(repOption, '[^A-Za-z]', '')}
    

    Or, if you’re already on Servlet 3.0 / EL 2.2 or newer (Tomcat 7 or newer), wherein EL started to support invoking methods with arguments, simply directly invoke String#replaceAll() method on the string instance.

    ${repOption.replaceAll('[^A-Za-z]', '')}
    

    See also:

    • How to call parameterized method from JSP using JSTL/EL
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to load the i18n localization properties of my Spring web application as
I'm working on a Spring application that simply searches a set of data for
currently I am working on a spring based application. I do have some unit
I am working on a Spring web application where I have a need to
I am working on a Spring web application and need to implement a simple
I've try to implement integration tests for a working application (spring, hibernate, soap, cxf).
I am working on an application using Spring 3 and Hibernate 3.5 with Java
I am working on profiling a legacy application using Spring AOP and I want
I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
I am working on a Spring application using Tomcat 6 and Spring 2.5 .

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.