Struts2 <s:textarea>文本域實例

在Struts2,你可以使用<s:textarea>創建HTML textarea文本域。爲了比較直觀的學習,這裏創建一個web工程爲:struts2textarea。整個工程的目錄結構如下:

Struts2

<s:textarea label="Address" name="address" cols="40" rows="10"/>

它會呈現爲如下面的HTML代碼。

Struts 2 <s:textarea> 示例

頁面包含一個地址textarea字段域,並顯示 textarea的值在表單提交後。

1. Action

TextAreaAction.java

package com.yiibai.common.action;

import com.opensymphony.xwork2.ActionSupport;

public class TextAreaAction extends ActionSupport{

private String address;

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String execute() {
    return SUCCESS;
}

}

2. 視圖頁面

Struts2的「s:textarea」標籤來創建一個textarea文本域字段。

textarea.jsp

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

Struts2 文本域實例

<s:form action="helloTextarea" namespace="/">

<s:submit value="submit" name="submit" />

welcome.jsp

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

Struts2文本域實例

3. struts.xml

/pages/textarea.jsp /pages/welcome.jsp

4. 運行結果

http://localhost:8080/struts2textarea/textarea.action

* Struts2
*

參考

  1. Struts 2 textarea文檔
0 條評論,你可以發表評論,我們會進行改進
Comment author placeholder