3

I have an application in struts 2.3 and handled all requests by '/*' pattern to go to my struts application in web.xml it's ok and requests are comes in struts application. but problem is here in my struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

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

   <package name="default" namespace="/" extends="struts-default">
      <action name="en/*" class="ir.mr.khatami.action.SensationalRequestAction" method="respond">
        <param name="locale">en</param>
        <result name="reload">pages/sensational.jsp</result>
      </action>

   </package>

</struts>

in Web.xml i have

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

urls : localhost:8080/en , localhost:8080/en123 are ok

but i want something like this :

localhost:8080/en/something

and

localhost:8080/en/something/more

also i tried en** and /en** and /en/** but no result.

this is error i recieved on this url localhost:8080/en/something

HTTP Status 404 - /exciting/en/pages/sensational.jsp // exciting is root in my app.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. – Roman C Jun 19 '16 at 11:43
  • Read http://struts.apache.org/docs/namespace-configuration.html and http://struts.apache.org/docs/wildcard-mappings.html#WildcardMappings-Parametersaftertheactionname. – Aleksandr M Jun 21 '16 at 07:00
  • @AleksandrM Can you please update the link, both links shows `404 Page Not Found`? – Kavin Raju S Feb 09 '22 at 02:35

1 Answers1

1

Please review

https://struts.apache.org/docs/wildcard-mappings.html

The advanced title mention:

From 2.1.9+ regular expressions can be defined defined in the action name. To use this form of wild card, the following constants must be set:

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

So your mapping must be

<action name="en/{type}" ...

You can read the type value in your action by simply adding String type with setter and getters.

PS: I can not test it right now but it seems to work

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
  • actually type don't needed to be stored some where. i just wanted to localize my site from any url after /en . – Mohammadreza Khatami Jun 23 '16 at 08:14
  • ` ` I have this in my struts.xml, along with the xml tag for patternMatcher with the value of regex. But I get the error `There is no Action mapped for action name 2` when I access using the URL `http://localhost:8080/wildcard_sample/2/hello/3.json`. I am using `Struts 2.5.29`. @Alireza – Kavin Raju S Feb 09 '22 at 02:38