【问题标题】:404 error when Struts2 action extension is set to emptyStruts2 操作扩展设置为空时出现 404 错误
【发布时间】:2015-08-11 11:15:09
【问题描述】:

我想删除 Struts2 应用程序中的操作后缀扩展。

<constant name="struts.action.extension" value=""/> 添加到struts.xml 但是 Apache 服务器抛出 404 错误。

HTTP 状态 404 - 没有为命名空间 [/] 和操作映射操作 与上下文路径 [/Ideck_V3] 关联的名称 [login.jsp]。

我在第一页使用web.xml 中的welcome-file-list。 这里是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>

我该如何解决这个问题?

【问题讨论】:

标签: java configuration struts2 action-mapping


【解决方案1】:

默认扩展映射为",,action"。这意味着您可以使用映射到带有.action 后缀的操作名称,也可以不使用它,因此如果要删除操作后缀扩展名,您需要在struts.xml 中指定它为

<constant name="struts.action.extension" value=","/>

注意,没有动作后缀的动作映射仍然存在。它允许解析 url 中的扩展,例如 .jsp,并且不要将其与操作名称混淆。

【讨论】:

【解决方案2】:

由于您没有为您的操作设置任何扩展名,因此“/*”中的所有内容(请参阅您的 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"/>

【讨论】:

  • 感谢您的解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
  • 2017-09-16
  • 2014-02-24
  • 2014-03-24
  • 1970-01-01
  • 1970-01-01
  • 2011-09-05
相关资源
最近更新 更多