【问题标题】:Tomcat giving error : "There is no Action mapped for action name" in Struts 2 [duplicate]Tomcat给出错误:Struts 2中的“没有为动作名称映射的动作”[重复]
【发布时间】:2013-08-13 19:12:30
【问题描述】:

尝试更改struts.xml 的位置,但仍然出现错误。此外,在 URL 中使用的命名空间仍然出现错误。

struts.xml:

 <?xml version="1.0" encoding="UTF-8"?>    
 <!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd">   
   
   <struts>
    
        <package name="default" namespace="/program" extends="struts-default">
                
        <action name="getTwo" class="StrutsTwopack.ProgramTwo">
            <result>/success.jsp </result>
            <result>/failure.jsp</result>
        </action>   
                
        </package>
   
   </struts>

    

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>StrutsStart</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.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>

动作类:

package ninad.Struts2One;

import service.ProgramBest;

public class ProgramOneAction {
    
    private String bestprog;
    private String Lang;
    
    public String execute()
    {
        ProgramBest pb = new ProgramBest();
        setBestprog(pb.giveBestProgram(getLang()));
        System.out.println(bestprog);
        //System.out.println(getLang());
        return "success";
    }

    public String getBestprog() {
        return bestprog;
    }

    public void setBestprog(String bestprog) {
        this.bestprog = bestprog;
    }
    
    public String getLang() {
        return Lang;
    }

    public void setLang(String Lang) {
        this.Lang = Lang;
    }


}

服务类:

package service;

public class ProgramBest {

    public String giveBestProgram(String lang) {
        if (lang.equals("java")){
        return "My code";
        }
        else
            return "no other code";
    }

}

        

我在 Apache 窗口中输入的 URL 是:

http://localhost:8484/StrutsStart/program/ProgramOne.action

我得到的错误是:

There is no Action mapped for action name ProgramOne. - [unknown location]

【问题讨论】:

  • struts.xml的位置在哪里?
  • 它在 src 中。我也试过把它移到 web-inf 文件夹,但还是不行
  • 不知道它在哪里部署它是无关紧要的。

标签: java struts2 url-mapping xml-configuration


【解决方案1】:

你已经发布了一个问题

'Struts2中没有为动作名称getTwo映射的动作

动作getTwo 映射到命名空间/program 中的类StrutsTwopack.ProgramTwo。如果错误为真,则表示 URL 中的类错误或命名空间错误。

【讨论】:

  • 添加了工作代码。请检查一下
  • @user2679726 ProgramOne 是另一个未映射到您的代码的操作。
猜你喜欢
  • 1970-01-01
  • 2011-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多