java - Tomcat giving Error : "There is no Action mapped for action name" in Struts 2 -
this question has answer here:
tried changing location of struts.xml
still getting error. namespace being used in url still getting 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 enter in apache window :
http://localhost:8484/strutsstart/program/programone.action
the error is:
there no action mapped action name programone. - [unknown location]
you have posted question
'there no action mapped action name gettwo' in struts2
the action gettwo
mapped class strutstwopack.programtwo
in namespace /program
. if error true means either class wrong or namespace wrong in url.
what should do???
post sscce, or decide wrong version better resolvable.
Comments
Post a Comment