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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:20:20+00:00 2026-05-21T03:20:20+00:00

I’m trying to map my Struts actions using wildcards. Before, I used UrlRewrite Filter

  • 0

I’m trying to map my Struts actions using wildcards.

Before, I used UrlRewrite Filter by Tuckey. But this question changed my mind.

So here’s my problem: My URL’s look like the following:

  • www.example.com/promoties/category-123
  • www.example.com/promoties/category-123/subcategory-456

In these examples, the words category and subcategory are dummy data used to make the URL more relevant for search engines.

Now I’d like to ignore this dummy data, as I’m just interested in the (last) ID. In the first case 123 in the last case 456.

I’ve tried the following without success:

<package name="promoties" namespace="/promoties" extends="struts-default">
    <action name="([0-9a-zA-Z\-_]+)-{id:([0-9]+)}$" class="CategoryAction">
        <result type="tiles">categorydetail</result>
    </action>
</package>

Using following options in my struts.xml:

<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />

Has anyone tried this before? How would I go about doing this in Struts2?

  • 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-21T03:20:21+00:00Added an answer on May 21, 2026 at 3:20 am

    One way is to use simple wild card mapping and regulate the validation of the id component to struts2 validation. Here is an example which has been tested, but without validation.

    struts.xml you’ll see an action defined for category-* and category-*/subcategory-* in the second we’ll just keep the second wild card.

    <struts>
        <constant name="struts.enable.DynamicMethodInvocation" value="false" />
        <constant name="struts.devMode" value="true" />
        <constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
        <constant name="struts.enable.SlashesInActionNames" value="true"/>
        <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
        <package namespace="" name="default" extends="struts-default">
            <action name="category-*" class="test.TestBean">
                <param name="id">{1}</param>
                <result>/WEB-INF/content/test/results.jsp</result>
            </action>
            <action name="category-*/subcategory-*" class="test.TestBean">
                <param name="id">{2}</param>
                <result>/WEB-INF/content/test/results.jsp</result>
            </action>
        </package>
    </struts>
    

    test.TestBean here I used a String but in your case you’ll change this to int or Integer. You’ll want to validate that we did get an integer using validation xml or simply implementing com.opensymphony.xwork2.Validateable.

    package test;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class TestBean extends ActionSupport{
        //public to avoid get/set to make example shorter
        public String id;
    }
    

    /WEB-INF/content/test/results.jsp

    <%@taglib prefix="s" uri="/struts-tags"%>
    <html>
        <body>
            <h1>Wild Card Value</h1>
            id: <s:property value="id"/>
        </body>
    </html>
    

    Example 1
    The url: example.com/category-helloBart produces…

    Wild Card Value

    id: helloBart

    Example 2
    The url: example.com/category-helloBart/subcategory-123 produces…

    Wild Card Value

    id: 123

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

Sidebar

Related Questions

No related questions found

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.