我想在Struts2应用程序中删除动作后缀扩展名。
将<constant name="struts.action.extension" value=""/>
添加到struts.xml
但Apache服务器抛出404错误。
HTTP状态404 - 没有映射名称空间[/]和操作的Action 名称[login.jsp]与上下文路径[/ Ideck_V3]相关联。
我在welcome-file-list
中使用web.xml
作为第一页。
这是web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>com.hbs.ideck.common.Struts2Dispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
以下是struts.xml
<!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.action.extension" value=""/>
<include file="user.xml"/>
<include file="vendor.xml"/>
<include file="settings.xml"/>
</struts>
我该如何解决这个问题?
答案 0 :(得分:1)
由于你没有为你的行动设置任何扩展,所以#34; / *&#34; (见你的web.xml)被截获。如果你想过滤所有内容并且不设置任何扩展名,那么一切都将成为struts的一个动作。
您可以尝试仅过滤路径
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/actions/*</url-pattern>
</filter-mapping>
或者您必须设置扩展程序
<constant name="struts.action.extension" value="action" />
或排除某些模式
<constant name="struts.action.excludePattern" value="A REGEX"/>
答案 1 :(得分:1)
默认扩展名映射为",,action"
。这意味着您可以使用映射到带有.action
后缀的操作名称,如果您要删除操作后缀扩展名,则需要在struts.xml
中将其指定为
<constant name="struts.action.extension" value=","/>
注意,仍然保留没有操作后缀的映射到操作。它允许解析网址中的扩展程序,例如.jsp
,并且不要使用操作名称搞清楚。