struts2 convention插件无法正常工作
我试图用常规插件Struts2运行应用程序。 使用如下配置的struts.xml
,应用程序很好:
/index.jsp hey
现在我删除了struts.xml
并添加了一些这样的注释:
@Namespace("/") @ResultPath(value="/") public class CountryAction extends ActionSupport implements ModelDriven{ private List 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 getWorldCountry() { return worldCountry; } public void setWorldCountry(List worldCountry) { this.worldCountry = worldCountry; } @Override public Country getModel() { return country; } }
但是当我尝试运行应用程序时,我收到以下错误:
消息:
There is no Action mapped for namespace [/] and action name [hey] associated with context path [/JustStruts2].
我的web.xml
是这样的:
struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts.devMode true struts2 /*
在我做错的地方,任何帮助将不胜感激。
问候。
根据消息,Struts告诉你[hey]
你的动作配置中没有找到。 在struts.xml
您没有使用斜杠定义它。 在注释中执行相同操作。 不要映射可由容器本身处理但不由Struts2处理的index.jsp
。 默认情况下使用名称“success”,因此没有必要。
@Action(value="hey", results = { @Result(location="/page.jsp") })
请注意, @ResultPath
不是必需的。