java - struts2 conventions plugin not working properly -
i trying run application convention plugin struts2. application fine struts.xml
configured this:
<struts> <package name="struts2demo" extends="struts-default"> <action name="hey" class="action.countryaction" method="get"> <result name="success">/index.jsp</result> </action> <action name="add" class="action.countryaction" method="add"> <result type="redirect" name="success">hey</result> </action> <!-- add actions here --> </package> </struts>
now removed struts.xml
, added annotations this:
@namespace("/") @resultpath(value="/") public class countryaction extends actionsupport implements modeldriven<country>{ private list<country> worldcountry; private country country = new country(); public country getcountry() { return country; } public void setcountry(country country) { this.country = country; } // httpservletrequest request; @action(value="/hey",results={@result(name="success",location="/index.jsp")}) public string get() throws sqlexception { countryservice cs = new countryservice(); setworldcountry(cs.getcountry()); // system.out.println(getworldcountry()); return success; } public list<country> getworldcountry() { return worldcountry; } public void setworldcountry(list<country> worldcountry) { this.worldcountry = worldcountry; } @override public country getmodel() { return country; } }
but when trying run application getting following error:
messages:
there no action mapped namespace [/] , action name [hey] associated context path [/juststruts2].
my web.xml
this:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class> <init-param> <param-name>struts.devmode</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
where doing wrong, appreciated.
regards.
according message struts inform [hey]
not found in action configuration. in struts.xml
defined without slash. same in annotation. don't map index.jsp
handled container not struts2. name "success" used default, it's not necessary.
@action(value="hey", results = { @result(location="/page.jsp") })
note @resultpath
not necessary.
Comments
Post a Comment