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]. 
내가 잘못하고있는 중이 야

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

는, 어떤 도움이 이해할 수있을 것이다 :

web.xml이있다.
감사합니다.

+0

asm-commons.jar 이것을 해결하려면 – Aadam

답변

3

메시지에 따르면 Struts는 작업 구성에 [hey]을 찾을 수 없음을 알립니다. struts.xml에서는 슬래시를 사용하지 않고 정의했습니다. 주석에서 동일한 작업을 수행하십시오. 컨테이너 자체는 처리 할 수 ​​있지만 Struts2는 처리 할 수없는 index.jsp을 매핑하지 마십시오. "성공"이라는 이름이 기본적으로 사용되므로 필요하지 않습니다.

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

@ResultPath은 필요하지 않습니다.

+0

답장을 보내 주셔서 감사합니다. @Action (value = "hey", results = {@Result (location = "/ success.jsp")})으로 변경하고 @ResultPath를 제거했습니다. 여전히 같은 문제. 다른 해결책은 제발, 그물에서도 찾을 수 없습니다. : – Aadam

+0

내가주는 URL은 http : // localhost : 8084/JustStruts2/hey – Aadam

+0

입니다. hey.action을 시도 했습니까? index.jsp의 이름을 변경 했습니까? 또한 classpath에 규칙 플러그인이 있습니다. –