Reputation: 1332
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.
Upvotes: 3
Views: 421
Reputation: 45495
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
Upvotes: 1