zoukankan      html  css  js  c++  java
  • 【问题管理】-- 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

  • 相关阅读:
    JS闭包
    webpack管理资源
    在webpack中使用配置文件
    webpack起步
    buuctf-MISC 面具下的flag
    Kali linux Steghide开源隐写工具
    buuctf-misc 九连环
    buuctf-Crypto rsarsa 1
    buuctf-web HardSQL 1
    buuctf-web Hack World 1
  • 原文地址:https://www.cnblogs.com/yif0118/p/12723279.html
Copyright © 2011-2022 走看看