我在 struts 2.3 中有一个应用程序并通过 '/*' 模式处理所有请求以转到我在 web.xml 中的 struts 应用程序 没关系,请求来自 struts 应用程序。 但问题出在我的 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>
我在 Web.xml 中有
<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 都可以
但我想要这样的东西:
localhost:8080/en/something
和
localhost:8080/en/something/more
我也尝试了 en** 和/en** 和/en/** 但没有结果。
这是我在这个 url localhost:8080/en/something 上收到的错误
HTTP 状态 404 -/exciting/en/pages/sensational.jsp//exciting 是我应用程序的根。
最佳答案
请检查
https://struts.apache.org/docs/wildcard-mappings.html
高级标题提及:
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" />
所以你的映射必须是
<action name="en/{type}" ...
您可以通过简单地添加带有 setter 和 getter 的 String type
来读取操作中的 type
值。
PS:我现在无法测试它,但它似乎可以工作
关于struts2 - 特定的通配符模式在我的 struts.xml 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37906537/