Struts 2 If、ElseIf、Elseタグの例

Struts 2 If、ElseIf、Elseタグの例

ダウンロード–Struts2-If-ElseIf-Else-Tag-Example.zip

Struts 2If, ElseIf and Elseタグは、基本的な条件チェックを実行するために使用されます。

If‘タグは単独で使用できます


    This is String 1

または ‘Else If‘タグ付き


    This is String 1


    This is String 2

and/or single/multiple ‘Else‘ tag.


    This is String 1


    This is String 2


    Other Strings

上記の記述はすべて正しいです。 Struts 2 ‘If, ElseIf and Else‘タグの使用法を示す例を見てみましょう。

1. アクション

Struts 2」値を含むStringプロパティを持つActionクラス。

IfTagAction

package com.example.common.action;

import com.opensymphony.xwork2.ActionSupport;

public class IfTagAction extends ActionSupport{

    private String framework = "Struts 2";

    public String getFramework() {
        return framework;
    }

    public void setFramework(String framework) {
        this.framework = framework;
    }

    public String execute() {
        return SUCCESS;
    }
}

2. If、ElseIfおよびElseタグの例

framework」変数の条件チェックを実行するためのIf, ElseIf and Elseタグの使用を示すJSPページ。

if.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
 




Struts 2 If, Else, ElseIf tag example

This is Struts 2 This is Struts 1 Other framework

3. struts.xml

リンクしてください〜





    

    

        
            pages/if.jsp