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

问题背景:

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

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" />
    
    
    
    <constant name="struts.devMode" value="true" />
    <package name="default" namespace="/" extends="struts-default">
        <action name="index" class="cn.yif.action.UserAction" method="execute">
            
            <result name="success" type="dispatcher">
                /success.jsp
            result>
            
            <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 []。

【问题管理】-- Struts2配置struts.xml中Action访问报There is no Action mapped for namespace..._第1张图片

 

具体修改措施:

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

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 Blankdisplay-name>
    
        index.jsp
    
    <filter>
        <filter-name>struts2filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterfilter-class>
    filter>
    <filter-mapping>
        <filter-name>struts2filter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>
web-app>

 

最终问题得到解决:

【问题管理】-- Struts2配置struts.xml中Action访问报There is no Action mapped for namespace..._第2张图片

 

 参考博文:

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

 

你可能感兴趣的:(【问题管理】-- Struts2配置struts.xml中Action访问报There is no Action mapped for namespace...)