2010-07-13 3 views
1

최근에 Struts2 UI 태그에 대한 튜토리얼을 살펴 보겠습니다. 그래서, 나는 그 예를 발견하고 완벽하게 그것을 실행합니다.Struts2 구성 이해하기

그러나 struts.xml 구성 파일에서 일부 OGNL 표현식을 이해할 수 없었습니다. 여기 쓰고 난 것이이 RegisterAction.java로 리디렉션 등) (내 수업의 방법을 채우는 실행 그래서 여기

<struts> 
    <package name="default" extends="struts-default"> 
     <action name="*Register" method="{1}" class="nirmal.RegisterAction"> 
      <result name="populate">/register.jsp</result> 
      <result name="input">/register.jsp</result> 
      <result name="success">/success.jsp</result> 
     </action>   

    </package> 
</struts> 

내가 다음 예와 같이, index.jsp가에서 populateRegier에 하나 개의 요청을 채우는 오전 :

RegisterAction.java

package nirmal; 

import java.util.ArrayList; 

import com.opensymphony.xwork2.ActionSupport; 

public class RegisterAction extends ActionSupport { 

    private String userName; 
    private String password; 
    private String gender; 
    private String about; 
    private String country; 
    private ArrayList<Country> countryList; 
    private String[] community; 
    private ArrayList<String> communityList; 
    private Boolean mailingList; 

    public String populate() { 

     countryList = new ArrayList<Country>(); 
     countryList.add(new Country(1, "India")); 
     countryList.add(new Country(2, "USA")); 
     countryList.add(new Country(3, "France")); 

     communityList = new ArrayList<String>(); 
     communityList.add("Java"); 
     communityList.add(".Net"); 
     communityList.add("SOA"); 

     community = new String[]{"Java",".Net"}; 
     mailingList = true; 

     return "populate"; 
    } 
    public String execute() { 
     return SUCCESS; 
    } 
    public String getUserName() { 
     return userName; 
    } 
    public void setUserName(String userName) { 
     this.userName = userName; 
    } 
    public String getPassword() { 
     return password; 
    } 
    public void setPassword(String password) { 
     this.password = password; 
    } 
    public String getGender() { 
     return gender; 
    } 
    public void setGender(String gender) { 
     this.gender = gender; 
    } 
    public String getAbout() { 
     return about; 
    } 
    public void setAbout(String about) { 
     this.about = about; 
    } 
    public String getCountry() { 
     return country; 
    } 
    public void setCountry(String country) { 
     this.country = country; 
    } 
    public ArrayList<Country> getCountryList() { 
     return countryList; 
    } 
    public void setCountryList(ArrayList<Country> countryList) { 
     this.countryList = countryList; 
    } 
    public String[] getCommunity() { 
     return community; 
    } 
    public void setCommunity(String[] community) { 
     this.community = community; 
    } 
    public ArrayList<String> getCommunityList() { 
     return communityList; 
    } 
    public void setCommunityList(ArrayList<String> communityList) { 
     this.communityList = communityList; 
    } 
    public Boolean getMailingList() { 
     return mailingList; 
    } 
    public void setMailingList(Boolean mailingList) { 
     this.mailingList = mailingList; 
    } 
} 

첫 번째 질문 : 여기() 메소드를 채울 exeucting 왜 나는 이해할 수 없었다?

두 번째 질문 : struts2.xml에서 method="{1}"의 의미는 무엇입니까?

미리 감사드립니다 ...

+0

명확한 설명을주십시오 – SMS

답변

2

두 가지 질문에 동일한 대답이 있습니다. 당신이 당신의 스트럿츠 설정이 라인을 보면 :

<action name="*Register" method="{1}" class="nirmal.RegisterAction"> 

당신은 ***** 통지하고거야 {1}합니다. 어떤 struts가 수행중인 것은 populate 요청을 등록하고 위의 < 액션 >에 대해 와일드 카드를 수행하는 것입니다.

와일드 카드 일치 부분 (채우기)을 가져 와서 메서드 이름으로 사용합니다 ({1}을 채우기로 바꿉니다). 이것이 nirmal.RegisterAction 클래스에서 populate() 메서드가 호출되는 원인입니다.

같은 클래스에서 execute() 메소드를 호출하려면 executeRegister 요청을 보내야합니다. 스트럿츠 사이트에는 wildcard mappings에 대한 자세한 정보가 있습니다. 개인적으로 나는 그 (것)들을 윤곽을 청결하게 유지하기를 위해 아주 유용하다는 것을 찾아 냈다.

1

Populate 메서드가 호출되는 이유는 사용자가 선택하거나 보는데 도움이되는 자동 채워지는 데이터가 필요하기 때문입니다. 기본 선택에서도 도움이됩니다.

+0

이것에 대해 자세히 설명해 주시겠습니까? – Tyrsius