質問

最近私はStruts2 UIタグのための1つのチュートリアルで行っています。だから、私はその例を見つけて完璧でそれを実行しました。

しかし、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で1つのリクエストを入力しているので、registeraction.javaにリダイレクトして、私のクラスのPopulate()メソッドの実行、すなわち次のようにして説明します:

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

最初の質問:私はなぜそれがPopulate()メソッドがここで存在するのかを理解できませんでしたか?

2番目の質問: struts2.xmlのmethod="{1}"の意味は何ですか?

事前にありがとう...

役に立ちましたか?

解決

2つの質問は同じ答えを持っています。Struts Configのこの行を見ると:

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

*****と {1} に気づくでしょう。Strutsが何をしているのか上記のの上記のワイルドカードの一致を要求して実行する populateregister request>。

ワイルドカードマッチング部分(携帯)を取り、メソッド名として使用します({1}を{1}に置き換えます)。これは、Populate()メソッドをNirmal.RegisterActionクラスで呼び出す原因となります。

同じクラスでexecute()メソッドを呼び出したい場合は、executeRegister要求を送信します。> StrutsサイトのWildCard Mappings についての詳細情報があります。個人的には、Config Cleanを維持するのに非常に便利であることがわかりました。

他のヒント

Populateメソッドは、ユーザーがそれを選択するのに役立つ、またはそれを表示するのに役立つ、自動的に入力されるデータのいくつかが必要なので、デフォルトの選択に役立つように、自動的に入力されるためです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top