02: Spring MVC form submission tutorial step by step

This tutorial extends Spring MVC beginner tutorial step by step.

Maven project structure

Spring MVC form submission project structure

Model class to capture login form details

Step 1: Create a POJO “Login.java” in the package “com.mytutorial.model” under “src/main/java” to capture login form details like “user” & “password”.

Define the Controller

Step 2: Create a new controller “SimpleLoginController.java” in the package “com.mytutorial.controller”.

Define the Views

Step 3: The first view is to show the login form with “login.jsp” under “src/main/webapp/WEB-INF/views”.

Step 4: The second view is to display the login success message with “login-success.jsp” under “src/main/webapp/WEB-INF/views”.

The flow

simpleWeb/entry/ –> “SimpleLoginController.showForm()” –> login.jsp –> /simpleWeb/entry/login –> “SimpleLoginController.submit()” –> login-success.jsp

No changes to web.xml, applicationContext.xml & pom.xml

Same as Spring MVC beginner tutorial step by step.

Build the war & deploy to Tomcat

Same as Spring MVC beginner tutorial step by step.

Run it in a browser

http://localhost:8080/simpleWeb/entry/

Show login form & submit the login details

http://localhost:8080/simpleWeb/entry/login

login success message


300+ Java Developer Interview Q&As

800+ Java Interview Q&As

Top