Spring MVC Password Example - Spring MVC Framework

What is Spring MVC - Password Example?

The following example explains the readers on how to use Password in forms using Spring Web MVC framework. Firstly, a working Eclipse IDE should be in place and follow the steps below to create a Dynamic Form based Web Application




Create a project with a nameHelloWebunder a packagecom.wisdomjobsas explained in theSpring MVC - Hello World Examplechapter.


Create a Java classesUser,UserControllerunder thecom.wisdomjobs package.


Create a view filesuser.jsp,users.jspunderjspsub-folder.


The final step is to create the content of all the source and configuration files and export the application as explained below.



In the above example, we are creating a service method called user(). We are passing a blank User object in ModelAndView object. In this object, command name is specified because the framework expects an object with “command” name if we are using <form:form> tags in JSP file. user.jsp view is returned if user() method is called.

addUser() is the next method which is called against a POST method on HelloWeb/addUser URL. Model object is prepared based on the submitted information. A “users” view is returned from service method at the end which results in showing users.jsp.


We use <form:password/> tag to display a HTML password box. Example below-

It will give the following HTML content.


Once the source and configuration files are created export the application. Do right click on the application and Export > WAR File option and save HelloWeb.war file in Tomcat’s webapps folder.

Start the Tomcat Server and using a standard browser check if you are having access to other web pages from webapps folder. Try the URL http://localhost:8080/HelloWeb/user and you must see the below result if everything is fine with Spring Web Application:

 Spring Password Form

Submit the form once the required information is filled by clicking Submit button. You must see the below result if everything is fine with Spring Web Application:

 Spring Password Form

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Spring MVC Framework Topics