为什么struts2框架的通配符没效果报错了?

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">
    
<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="helloworld_*" method="{1}" class="com.imooc.action.HelloWorldAction">
            <result>/result.jsp</result>
            <result name="{1}">/{1}.jsp</result>
        </action>
    </package>

</struts>

HelloWorldAction.java

package com.imooc.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {
    
    public String execute() throws Exception{
        System.out.println("执行action");
        return SUCCESS;
    }
    
    public String add(){
        System.out.println("add");
        return SUCCESS;
    }
    
}
http://127.0.0.1:8080/HelloWorld/helloworld_add.action
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [helloworld_add] associated with context path [/HelloWorld].

报这个错误。。我明明是按照教程的写的啊?哪里出错了?

阅读 3.2k
3 个回答

namespace是不是应该为/HelloWorld

下划线改成中横线试试, 这个框架BUG众多,注意安全。

请问找到问题出在哪了吗?我最近也碰到这个问题了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题