4

我試圖運行帶有約定插件Struts2的應用程序。該應用程序是罰款struts.xml配置是這樣的:struts2約定插件不能正常工作

<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,並增加了一些註釋是這樣的:

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

,但是當我試圖運行該應用程序我得到以下錯誤:

消息:

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

web.xml是這樣的:

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

我哪裏做錯了,任何幫助將不勝感激。
此致敬禮。

+0

asm-commons.jar解決此問題 – Aadam 2016-06-22 08:43:58

回答

3

根據消息Struts通知您[hey]找不到您的操作配置。在struts.xml你沒有斜槓定義它。在註釋中做同樣的事情。不要映射index.jsp,它可以由容器本身處理,但不能由Struts2處理。名稱「成功」默認使用,所以沒有必要。

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

請注意,@ResultPath是沒有必要的。

+0

感謝您的回覆。我將它更改爲@Action(value =「hey」,results = {@Result(location =「/ success.jsp」)})並刪除了@ResultPath。仍然是同樣的問題。請任何其他解決方案,也不能在網上找到。 :( – Aadam 2013-04-05 09:37:23

+0

我給的網址是這個http:// localhost:8084/JustStruts2/hey – Aadam 2013-04-05 09:40:43

+0

你試過hey.action嗎?你重命名了index.jsp嗎?還有類路徑上的convention插件。 – 2013-04-05 09:42:06