java - Struts2操作扩展设置为空时出现404错误

标签 java configuration struts2 action-mapping

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

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

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login.jsp] associated with context path [/Ideck_V3].

我正在使用welcome-file-listweb.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>

我该如何解决这个问题?

最佳答案

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

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

请注意,没有操作后缀的操作映射仍然保留。它允许解析 url 中的扩展名,如 .jsp,并且不会与操作名称混淆。

关于java - Struts2操作扩展设置为空时出现404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31940293/

相关文章:

ruby-on-rails - 使用 Ruby on Rails 管理实时配置变量的最佳方法是什么?

java - Spring xml到java配置: how to convert nested xml bean definition

java - Struts Dojo 值(value)观的国际化

java - 处理动态 OSGi 服务依赖关系的最佳方法

java - 有什么方法可以在 cassandra 中实现无状态分页吗?

java - 如何从 Java 发送一封在 Outlook 中自动过期的电子邮件?

java - Jbehave boolean 命名参数

java - 正确使用 Apache Commons 配置

javascript - 如何为文本区域设置值,并使用struts2操作获取它?

struts2 - 具有属性但没有值的 Struts 2 TextField 标记