1. Overview

This article contains spring boot form submit example using JSP. The form has been submitted using post method and the controller will handle post using @PostMapping annotation. Submitted data has been transferred to another JSP using ModelMap.

2. Example

spring boot form submit example

spring boot form submit example

2.1 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <description>Here is example of spring boot form submit example</description>
    <!-- Inherit defaults from Spring Boot -->
        <!-- Provided -->
            <groupId>org.springframework.boot</groupId>                <!-- for tomcat web container-->
            <groupId>org.apache.tomcat.embed</groupId>              <!--fot jap compilation need provide scope runtime or provided because it available in tomcat -->
            <scope>runtime</scope>     <!-- in my case provided not working so write runtime-->
            <groupId>javax.servlet</groupId>           <!-- for jsp jstl tags-->
            <groupId>org.springframework.boot</groupId>         <!--its for spring mvc related -->

2.2 application.properties

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

2.3 SpringBootConfig

package com.javadeveloperzone;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

 * Created by JavaDeveloperZone on 19-07-2017.

// Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute
public class SpringBootConfig extends SpringBootServletInitializer {
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootConfig.class);

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootConfig.class, args);            // it wil start application

2.4 EmployeeController

package com.javadeveloperzone.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

 * Created by JavaDeveloperZone on 19-07-2017.
public class EmployeeController {

    public String getForm() {
        return "employeeFrom";

    @PostMapping("/saveDetails")                     // it only support port method
    public String saveDetails(@RequestParam("employeeName") String employeeName,
                              @RequestParam("employeeEmail") String employeeEmail,
                              ModelMap modelMap) {

        // write your code to save details
        modelMap.put("employeeName", employeeName);
        modelMap.put("employeeEmail", employeeEmail);
        return "viewDetails";           // welcome is view name. It will call welcome.jsp

2.5 employeeFrom.jsp

    <title>spring boot form submit example</title>
<h2>Employee Details</h2>
<form method="post" action="saveDetails">   // saveDetails url mapping in EmployeeController
    Enter Employee Name : <input type="text" name="employeeName"/>
    Enter Employee Email Address: <input type="email" name="employeeEmail">
    <input type="submit" value="Submit">

2.6 viewDetails.jsp

  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 16-08-2017
  Time: 08:02
  To change this template use File | Settings | File Templates.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <title>spring boot form submit example</title>
<h1>spring boot form submit example</h1>
<h2> Details as submitted successfully </h2>
<h4> Employee Name : ${employeeName} </h4>
<h4> Employee Email : ${employeeEmail} </h4>

2.7 Output

spring boot form submit example form

spring boot form submit example form

After form submit:

spring boot form submit example form submit success

spring boot form submit example form submit success

4. References

5. Source Code

spring-boot-form-submit-example (30 KB)


Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.

Leave a Reply

Your email address will not be published. Required fields are marked *