Struts 2 TextArea field is helpful for entering the multiple lines in the input box. It is similar to the textfiled tag, but in the textfield tag only one line can be entered. Lets look at the example.
1. Action Class
package javabeat.net.struts2; public class Struts2UITagsAction{ private String description; public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String execute(){ return "success"; } }
2. TextArea Tag Example
TextArea.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> </head> <body> <h1>JavaBeat - Struts 2 TextArea Tag Demo</h1> <s:form action="TextAreaDemo"> <s:textarea name="description" label="Description : " cols="40" rows="10" /> <s:submit label="Submit" /> </s:form> </body> </html>
Result.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <body> <h2>JavaBeat - Struts 2 TextArea Tag Demo</h2> <h4> Description : <s:property value="description" /><br> </h4> </body> </html>
3. Struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="uitagsdemo" extends="struts-default"> <action name="TextAreaDemo" class="javabeat.net.struts2.Struts2UITagsAction" > <result name="success">Result.jsp</result> </action> </package> </struts>
4. TextArea Tag Demo
If you access the application using URL http://localhost:8080/Struts2App/TextAreaDemo, you would see the following output.