Struts2 구성 이해
-
14-09-2020 - |
문제
최근에 Struts2 UI 태그에 대한 튜토리얼 한 튜토리얼을 사용하고 있습니다.그래서, 나는 그 예를 발견하고 그것을 완벽하게 실행한다.
그러나 struts.xml 구성 파일에서는 OGnl 표현식 중 일부를 이해할 수 없었습니다.여기에 쓰고있는 것 :
<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에서 하나의 요청을 채우고 있으므로 registaction.java를 registing.java 및 내 클래스의 populate () 메서드를 실행합니다.
registing.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;
}
}
.
첫 번째 질문 : 이유는 왜 그것이 왜 인류 () 메서드를 여기에있는 이유를 이해할 수 없었습니다.
두 번째 질문 : struts2.xml의 method="{1}"
의 의미는 무엇입니까?
미리 감사드립니다 ...
해결책
2 개의 질문은 동일한 대답을 가지고 있습니다.Struts Config 에서이 줄을 보면 다음을 참조하십시오.
<action name="*Register" method="{1}" class="nirmal.RegisterAction">
.
***** 및 {1} 을 알 수 있습니다.어떤 스트럿이하고있는 일은 populateregister 요청 및 위의
와일드 카드 일치 부분 (채우기)을 사용하고 메소드 이름 ({1}을 채우는 {1}으로 대체)으로 사용합니다.이는 nirmal.registeraction 클래스에서 populate () 메소드를 호출하게하는 원인이됩니다.
동일한 클래스에서 EXECUTE () 메서드를 호출하려면 ExecuteRegister 요청을 보낼 수 있습니다. 와일드 카드 맵핑 에 대한 자세한 정보가 있습니다.개인적으로 Config Clean을 유지하는 데 매우 유용하다는 것을 발견했습니다.
다른 팁
POPULE 메서드는 사용자가 사용자를 선택하거나 볼 수 있도록 자동 채우는 데이터가 필요하기 때문에 메소드는 기본 선택에 도움이됩니다.