Pages Navigation Menu

Coding is much easier than you think

Struts 2 <S:textarea> example

Struts 2 <S:textarea> example



In Struts 2 , you can use the <s:textarea> to create a HTML textarea field.

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

** UPDATE: Struts 2 Complete tutorial now available here.

Struts 2 <s:textarea> example

A page contains address textarea field, and displays the textarea value after the form is submitted.

1. Action class

package com.simplecode.action;

import com.opensymphony.xwork2.ActionSupport;

public class TextAreaAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private String address;
	public String getAddress() {
		return address;
	public void setAddress(String address) {
		this.address = address;
	public String execute() {
		return SUCCESS;


2. View page


Struts 2 €œs:textarea€ tag to create a textarea field.


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

	<h2>Struts 2 - &lt;s:textarea&gt; example</h2>

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

		<s:textarea label="Address" name="address" cols="50" rows="10" />
		<s:submit value="submit" name="submit" />




<%@ taglib prefix="s" uri="/struts-tags"%>
<title>Text area</title>
	<h2>Struts 2 - &lt;s:textarea&gt; example</h2>

	<s:property value="address" />



3. struts.xml


<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


	<constant name="struts.devMode" value="true" />

	<package name="textarea" namespace="/jsp" extends="struts-default">
		<action name="textarea">
	<action name="helloTextarea" class="com.simplecode.action.TextAreaAction">
		<result name="success">/jsp/result.jsp</result>



4. Demo




s:hidden box






About Mohaideen Jamil

I'm a Full stack developer of IT exp in J2EE, AngularJs, MicroServices, Docker, Spring (Boot, MVC, Cloud), Bluemix, DevOps. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

%d bloggers like this: