• 【问题管理】-- Struts2配置struts.xml中Action访问报There is no Action mapped for namespace...


    问题背景:

    在做Struts2学习的页面访问时,配置了如下的两个<action>返回结果视图:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">
    
    <struts>
        <constant name="struts.enable.DynamicMethodInvocation" value="false" />
        <!--开发模式;修改配置文件不需要重启服务器-->
        <!--指的struts.xml,其它的配置文件修改依然还是需要重启-->
        <!--自动重新加载配置文件,不一定会绝对成功。-->
        <constant name="struts.devMode" value="true" />
        <package name="default" namespace="/" extends="struts-default">
            <action name="index" class="cn.yif.action.UserAction" method="execute">
                <!--局部结果视图:在一个Action标签中配置,将<result>作为<action>子元素配置;只有这个Action可以使用-->
                <result name="success" type="dispatcher">
                    /success.jsp
                </result>
                <!--success与error都是逻辑视图名称,决定响应哪个结果-->
                <result name="error" type="dispatcher">
                    /error.jsp
                </result>
            </action>
            <action name="example" class="cn.yif.action.ExampleAction" method="test">
                <result name="testExample" type="dispatcher">
                    /WEB-INF/view/test.jsp
                </result>
            </action>
        </package>
    </struts>

    在访问第二个结果视图的Action页面时,直接抛出了Messages:

    • There is no Action mapped for namespace [/] and action name [testExample] associated with context path []。

    具体修改措施:

    在web.xml文件中做如下配置,修改默认访问的页面为index.jsp页面,只需修改<welcome-file-list>即可:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
        <display-name>Struts Blank</display-name>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <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>
    </web-app>

    最终问题得到解决:

     参考博文:

    https://blog.csdn.net/qq_41063141/article/details/88721547

  • 相关阅读:
    P4781 【模板】拉格朗日插值
    P1306 斐波那契公约数
    P1154 奶牛分厩
    P1028 数的计算
    P1445 [Violet]樱花
    2020 Multi-University Training Contest 4
    Codeforces Round #658 (Div. 2) D
    2020牛客暑期多校训练营(第八场) K
    Codeforces Round #659 (Div. 2)
    #10106. 「一本通 3.7 例 2」单词游戏
  • 原文地址:https://www.cnblogs.com/yif0118/p/12723279.html
Copyright © 2020-2023  润新知