Struts 2 textarea设置长宽高属性



Struts 2 <s:textarea> textarea设置长宽高属性。

 

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

 

 

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

It will render as the following HTML code.

 

 

<textarea name=”address” cols=”40″ rows=”10″ id=”formaction_address”></textarea>

Struts 2 <s:textarea> example

 

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

 

1. Action

 

TextAreaAction.java

 

 

package com.mkyong.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. View page

 

Struts 2 “s:textarea” tag to create a textarea field.

 

textarea.jsp

 

 

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

<html>

<head>

</head>

 

<body>

<h1>Struts 2 – textarea example</h1>

 

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

 

<h4>

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

</h4>

 

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

 

</s:form>

 

</body>

</html>

welcome.jsp

 

 

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

<html>

 

<body>

<h1>Struts 2 – textarea example</h1>

 

<h4>

<s:property value=”address”/>

</h4>

 

</body>

</html>

 

 

 

3. struts.xml

 

Link all together ~

 

 

<?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=”" namespace=”/” extends=”struts-default”>

<action name=”textarea”>

<result>pages/textarea.jsp</result>

</action>

<action name=”helloTextarea”

class=”com.mkyong.common.action.TextAreaAction”>

<result name=”success”>pages/welcome.jsp</result>

</action>

</package>

 

</struts>

4. Demo

 

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

 

 

 

Reference

1.Struts 2 textarea documentation

 

Tags : struts2 textarea


 

 

 

 

 

 

 

 

mkyong

 

Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

 

 

 

 

 

Related Posts

•Struts 2 + Spring 3 + Quartz 1.8 Scheduler Example

•Add maxlength on textArea using jQuery

•Google App Engine + Struts 2 example

•javax.swing.tree.TreeNode is a restricted class

•Struts 2 on GAE – Error: result ‘null’ not found

 

 

Popular Posts

•Top 8 Java People You Should Know

•Top 20 Java Websites

•Top 5 Free Java eBooks

•Top 10 Java Regular Expression Examples

•Top 5 Open Source Q&A Systems

 

 

 

 

 

You might also like following tutorials :

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Recent Posts

 

Ant – How to create a Java Project

 

 

 

 

Create a fat Jar file – Maven Assembly Plugin

 

 

 

 

Maven – Exclude log4j.properties in Jar file

 

 

 

 

Maven – Create a fat Jar file – One-JAR example

 

 

 

 

Java – Cron job to run a jar file

 

 

 

 

 

Popular Tutorials

 

Android Tutorial

 

 

 

 

JSF 2.0 Tutorial

 

 

 

 

Spring Tutorial

 

 

 

 

Maven Tutorial