0

Tried changing the location of struts.xml but still getting error. Also the namespace is being used in URL still getting the error.

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>

action class:

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;
    }


}

Service class:

package service;

public class ProgramBest {

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

}

        

the URL that I enter in the Apache window is :

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

The error I get is:

There is no Action mapped for action name ProgramOne. - [unknown location]
Roman C
  • 49,761
  • 33
  • 66
  • 176
ninad
  • 9
  • 3

1 Answers1

0

You have posted a question

'There is no Action mapped for action name getTwo' in struts2

the action getTwo mapped to class StrutsTwopack.ProgramTwo in namespace /program. If the error is true this means either class is wrong or namespace is wrong in the URL.

Roman C
  • 49,761
  • 33
  • 66
  • 176