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.
 
Example:

<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

 
TextAreaAction.java
 

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.
 

textarea.jsp
 

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

<body>
	<h2>Struts 2 - <s:textarea> example</h2>

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

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

	</s:form>

</body>
</html>

 
result.jsp
 

<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<title>Text area</title>
<body>
	<h2>Struts 2 - <s:textarea> example</h2>

	<s:property value="address" />

</body>
</html>

 

3. struts.xml

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

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

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

</struts>

 

4. Demo

 

http://localhost:8089/Struts2_Textarea/jsp/textarea

 

s:hidden box

 

 

Reference

 

  • Struts 2 textarea documentation

 

About Mohaideen Jamil