struts2约定插件无法正常工作

编程入门 行业动态 更新时间:2024-10-27 16:31:30
本文介绍了struts2约定插件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用约定插件Struts2运行该应用程序.像这样配置struts.xml的应用程序很好:

I was trying to run the application with convention plugin Struts2. The application was fine with struts.xml configured like 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 your actions here --> </package> </struts>

现在我删除了该struts.xml并添加了一些注释,如下所示:

now I removed that struts.xml and added some annotations like 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 I am trying to run the application i am getting the following error:

消息:

There is no Action mapped for namespace [/] and action name [hey] associated with context path [/JustStruts2].

我的web.xml是这样:

My web.xml is 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 I am doing wrong, any help will be appreciated. Regards.

推荐答案

根据Struts通知您[hey]的消息,在您的操作配置中找不到该消息.在struts.xml中,定义时没有斜杠.在注释中执行相同的操作.不要映射可能由容器本身而不是Struts2处理的index.jsp.默认情况下使用名称"success",所以没有必要.

According to the message the Struts inform you [hey] not found in your action configuration. In the struts.xml you defined it without slash. Do the same in the annotation. Don't map index.jsp that could be handled by the container itself but not by Struts2. The name "success" is used by default, so it's not necessary.

@Action(value="hey", results = { @Result(location="/page.jsp") })

请注意,不需要@ResultPath.

更多推荐

struts2约定插件无法正常工作

本文发布于:2023-07-25 09:03:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   插件   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!