Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Spring - MVC TextArea
Next article icon

Spring - MVC TextArea

Last Updated : 24 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Here we will be learning about the Spring MVC TextArea form tag. We will create a basic Spring MVC project in the Spring tool suite(STS) to get some data from the user using the TextArea form tag. 

spring-form.tld

We can use Java Server Pages (JSPs) as a view component in Spring Framework. To help you implement views using JSP, the Spring Framework provides a form tag library namely spring-form.tld with some tags for evaluating errors, setting themes, formatting the fields for inputting and outputting internationalized messages.

'textarea' tag: The textarea is one of the tag provided by the spring-form.tld library. It renders an input HTML 'textarea'. Below are the various attributes available in textarea tag.

Attributes in 'textarea' tag

1. HTML Standard Attributes

HTML Standard attributes are also called global attributes that can be used with all HTML elements.

Attribute NameDescription
accesskeyTo specify a shortcut key to activate/focus on an element.
idTo specify a unique ID for the element.
langTo specify the language of the content.
tabindexTo specify tabbing order of an element.
titleTo specify extra information about the element.
dirTo specify text direction of elements content.

2. HTML Event Attributes

HTML Event Attributes are used to trigger a function when a particular event occurred on the element.

Attribute NameDescription
onblurTo execute a javascript function when a user leaves the text field.
onchangeTo execute a javascript function when a user changes the text.
onclickTo execute a javascript function when the user clicks on the field.
ondblclickTo execute a javascript function when the user double clicks on the element.
onfocusTo execute a javascript function when the user focuses on the text box.
onkeydownTo execute a javascript function when the user is pressing a key on the keyboard.
onkeypressTo execute a javascript function when the user presses the key on the keyboard.
onkeyupTo execute a javascript function when the user is releasing the key on the keyboard.
onmousedownTo execute a javascript function when the user is pressing a mouse button.
onmousemoveTo execute a javascript function when the user is moving the mouse pointer.
onmouseoutTo execute a javascript function when the user is moving the mouse pointer out of the field.
onmouseoverTo execute a javascript function when the user is moving the mouse pointer onto the field.
onmouseupTo execute a javascript function when the user is releasing the mouse button.
onselectTo execute a javascript function when the user selects the text.

3. HTML Required Attributes

Attribute NameDescription
colsTo specify the column value of the text area.
rowsTo specify the row value of the text area.

4. Other HTML Attributes

Attribute NameDescription
cssClassTo specify a class name for an HTML element to access it.
cssStyleTo add styles to an element, such as color, font, size, etc.
cssErrorClassUsed when the bounded element has errors.
disabledTo specify the element to be disabled or not.
htmlEscape To enable/disable HTML escaping of rendered values.
pathTo specify the path to a property for binding the data.
readonlyTo make the HTML element read-only field.

Spring MVC Application

Below is the application we will be creating.

Spring MVC Textarea - Example application

Procedure

The steps to create an application is as follows: 

Step 1: Create a Spring MVC project in Spring Tool Suite.

Step 2: In STS, while creating the project based on the developer selection, it will download all the required maven dependencies, *.jar, lib files and it will provide an embedded server.

Step 3: Below is the final project structure of the Spring MVC project after creating *.java and *.jsp files also.

final project structure of the Spring MVC project after creating *.java and *.jsp files
Project Structure

Implementation

Files to be created are as follows: 

  • Note.java: Bean class to define the properties and getter/setter methods of the properties.
  • NoteController.java: Controller class to process the request and generate the output.
  • note.jsp: Jsp file to get the input from the user from the browser.
  • noteSummary.jsp: Jsp file to display the processed output to the user.

A. File: note.jsp

HTML
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ page session="false"%> <html> <head> <title>GeeksforGeeks - Note</title> </head> <body>     <h1>Welcome to GeeksforGeeks!</h1>      <form:form action="submit" method="post" modelAttribute="note">         <table>             <tr>                 <td><form:label path="noteDetail">Feedback Note: </form:label></td>                 <td><form:textarea id="feedBack" path="noteDetail" rows="5" cols="40" title="GFG"                                      onfocus="color()" onblur="remove()" cssStyle="font-style:italic"/></td>             </tr>             <tr>                 <td><form:button>Submit</form:button></td>             </tr>         </table>     </form:form>          <script type="text/javascript">          function color() {           document.getElementById("feedBack").style.backgroundColor = "CBF7C7";         }          function remove() {           document.getElementById("feedBack").style.backgroundColor = "FFFFFF";         }     </script> </body> </html> 


This is the JSP page that interacts with the user to get the information. Inside the form, to display the fields properly, we are using a table tag. Provide a label and the text area to enter some data in it using the form tag - textarea. The tag textarea will internally provide an HTML textarea box while processing.

B. File: Note.java

Java
// Java Program to Illustrate Note Class  package com.geek.app;  // Class public class Note {      public String noteDetail;      // Method     public String getNoteDetail() { return noteDetail; }      // Method     public void setNoteDetail(String noteDetail)     {         this.noteDetail = noteDetail;     } } 
  • This is the Java Bean class to define the properties.
  • Create noteDetail property to input the user entered data in it.
  • Generate getter/setter methods of the property to get/set the value of the property.

C. NoteController.java

Java
package com.geek.app;  import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod;  @Controller public class NoteController {      @RequestMapping(value = "/")     public String viewNote(Model model) {         Note note = new Note();         model.addAttribute("note", note);         return "note";     }      @RequestMapping(value = "/submit", method = RequestMethod.POST)     public String submitNote(@ModelAttribute("note") Note note) {         return "noteSummary";     }  } 

This is the Spring controller class where it process the methods based on the mapping of the requests. Here, @Controller, conveys to the container that this class is the spring controller class. The annotation, @RequestMapping, maps the request URL's to the specified method based on the value provided.

D. noteSummary.jsp

HTML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>GeeksforGeeks - Feedback Summary</title> </head> <body>      <h2>Feedback submitted successfully!</h2>      <span>Feedback details: </span>     <span>${note.noteDetail}</span>  </body> </html> 
  • This is the Jsp page to display the output of the processed input.
  • When the controller process the input, we are displaying the output to the user using this Jsp page.

Execution

  • After creating all the required java and jsp files, run the project on the server.
  • Right on the Project, Run as -> Run on the server.
  • Select the server in the localhost to run the application.
  • Open the URL: http://localhost:8080/app/ in the browser to get the below screen.
Welcome page - note.jsp
  • As we provided different attributes to the textarea , we can see those functionality.
HTML
<form:textarea id="feedBack" path="noteDetail" rows="5" cols="40" title="GFG"                  onfocus="color()" onblur="remove()" cssStyle="font-style:italic"/> 
  • As we discussed above, id attribute specifies the ID for the text box.
  • path attribute specifies the pathname to which the entered data has to be bind.
  • rows attribute specifies the number of rows that can be entered in the text box.
  • cols attribute specifies the number of columns that can be entered in the text box.
  • title attribute displays the value given - GFG with the cursor on the text box.
  • onfocus, onblur is the event attributes that execute the respective functions when the event occurred.
  • cssStyle attribute can be used to provide any styles to the entered data in the text box like font color, font style, font family, etc.
title attribute
  • We can see the value GFG on the textarea box when the cursor is placed on the text box as we specified the attribute title="GFG".
  • Once you click on the text box, the color will change based on the onfocus attribute like below.
onfocus attribute
  • Enter the data in the text box and click on submit.
cssStyle attribute
  • As we specified the attribute cssStyle = "font-style:italic", the text entered by the user have the italic font.
  • Once the page is submitted, based on the URL mapping, the controller class will execute the submitNote method in it and provides the below output.
Output - noteSummary.jsp

This way we can use the tag - textarea in forms with the required attributes based on the requirement provided while developing Spring MVC applications. 


Next Article
Spring - MVC TextArea

Y

yaminitalisetty
Improve
Article Tags :
  • Java
  • Geeks Premier League
  • Geeks-Premier-League-2022
  • Java-Spring
  • Java-Spring-MVC
Practice Tags :
  • Java

Similar Reads

    Spring MVC Application Without web.xml File
    Spring MVC framework enables separation of modules namely Model, View, and Controller, and seamlessly handles the application integration. This enables the developer to create complex applications also using plain java classes. Here we will be creating and running Your First Spring MVC Application,
    4 min read
    Spring - MVC Listbox
    Spring Web MVC framework to demonstrate how to utilize Listbox in forms. Let's start by setting up an Eclipse IDE and then following the steps to create a Dynamic Form-based Web Application utilizing the Spring Web Framework. The items are listed in the Spring MVC form Listbox. This tag creates a se
    4 min read
    Spring MVC - Multiple Resolver Mapping
    Spring MVC Framework provides the feature of View Resolver through which you can map a view to its respective view and render the model in your browser. The View Resolver eliminates the use of view technologies like Velocity and JSP. There are many view resolvers available in spring-like InternalRes
    4 min read
    How to Extract TV Show Details via REST API and Spring MVC?
    REpresentational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services. REST API is a way of accessing web services in a simple and flexible way without having any processing. Spring MVC is a Web MVC Framework for building web applicat
    9 min read
    Spring MVC File Upload
    Spring MVC provides a robust mechanism for handling file uploads in web applications. Using Spring MVC file upload, developers can easily integrate multipart file handling with the CommonsMultipartResolver. This article covers how to upload files in Spring MVC, configure MultipartResolver, and manag
    6 min read
    Spring MVC - Tiles
    Spring provides functionality for integrating with the Apache Tiles framework. With the help of spring tiles support, we can easily manage the layout of the Spring MVC application. Benefits of Spring MVC's Tiles support: The following are some of the primary benefits of Spring MVC Tiles 3 Integratio
    4 min read
    Spring MVC - Text Box
    To begin, make sure you have a working Eclipse IDE installed and follow the steps below to create a Spring Web Framework-based Dynamic Form-based Web Application. Steps to create TextBox in Spring MVC: Create a SpringMVCTextField project in the com.geeksforgeeks package.Under the com.geeksforgeeks p
    3 min read
    Spring MVC - Multiple Controller
    We may construct numerous controllers at once in Spring MVC. Each controller class must be annotated with the @Controller annotation. A Spring MVC example with numerous controllers can be found here. The procedure is as follows: In the case of Maven, load the spring jar files or add dependencies.Mak
    2 min read
    Spring MVC - Model Interface
    The Spring Web model-view-controller (MVC) is an open-source framework used to build J2EE web applications. It is based on the Model-View-Controller design pattern and implements the basic features of a core spring framework - Dependency Injection. It is designed around a 'DispatcherServlet' that di
    7 min read
    Spring MVC - Number Validation
    The Spring Web model-view-controller (MVC) is an open-source framework used to build J2EE web applications. It is based on the Model-View-Controller design pattern and implements the basic features of a core spring framework - Dependency Injection. It is designed around a 'DispatcherServlet' that di
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences