• 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

     

  • 相关阅读:
    分布式计算框架——MapReduce
    Hadoop总结
    HBase原理总结
    LeetCode牛客148题
    LeetCode刷题[Python版]
    【Linux】netstat命令详解
    基于docker搭建Prometheus+Grafana监控(一)
    Zabbix笔记一:zabbix安装
    【Linux】vi/vim中如果替换
    【redis】Redis学习:redis测试注意点
  • 原文地址:https://www.cnblogs.com/bigorang/p/6680559.html
Copyright © 2020-2023  润新知