There is no Action mapped for namespace / and action name 通配符的问题

之前看了一些struts2的视频。

现在复习了下 struts2.发现了这个问题

网上的说的解决办法大都没提到这个问题,1%的文章提到了新版本的struts中 method的问题

There is no Action mapped for namespace / and action name XXX

http://localhost:8080/Struts2Learn/loginAction_login.action

原因不详。


 

解决办法:

 

通配符  *  的使用方法中。

 

struts-2.5.10.1版本下,struts.xml中 action 的配置里面   不需要指定method 属性

struts.xml

复制代码
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <!DOCTYPE struts 
 4 PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
 5  "http://struts.apache.org/dtds/struts-2.5.dtd" >
 6 <struts>
 7     <package name="user" namespace="/" extends="struts-default">
 8         <action name="loginAction_*" class="com.learn.LoginAction" method={1}>  <!--不需要method={1}-->
 9             <result name="success">/loginSuccess.jsp</result>
10             <result name="fail">/loginFail.jsp</result>
11         </action>
12     </package>
13 </struts>
复制代码
com.learn.LoginAction

复制代码
 1 package com.learn;
 2 
 3 import com.opensymphony.xwork2.ActionSupport;
 4 
 5 public class LoginAction extends ActionSupport {
 6 
 7     private static final long serialVersionUID = 1L;
 8     private String username;
 9     private String password;
10 
11     public String getUsername() {
12         return username;
13     }
14 
15     public void setUsername(String username) {
16         this.username = username;
17     }
18 
19     public String getPassword() {
20         return password;
21     }
22 
23     public void setPassword(String password) {
24         this.password = password;
25     }
26     public String loginn() throws Exception {
27         System.out.println("login()");
28         return "success";
29 
30     }
31 
32 }
复制代码

访问连接

 

http://localhost:8080/Struts2Learn/loginAction_loginn.action

 

posted @   BigOrang  阅读(8151)  评论(3编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示