Solution 1 :

First you correct the action spelling in 2nd form in your hello.html also use th:action for form action as you have used Thymeleaf. Also, you have not closed your name="text1" in your first form.

<input type="text" name="text1 th_value="${text1_value}"/>

change it to

<input type="text" name="text1" th_value="${text1_value}"/>
   <form th_action="@{/hello}" method="post">
            Enter a word:
            <input type="text" name="text1" th_value="${text1_value}">
            <input type="submit" value="Click">
        <form  th_action="@{/hello/db}" method="post" >
            Enter Employee ID:
            <input type="number" name="text2" th_value="${text2_value}" >
            <input type="submit" value="Click" >

Problem :

I am trying to get an Employee’s info from a database with a user-input ID number in the html page hello.html and display the info in another html file helloResponseDB.html, but it seems that when I submit the ID number, it leads me to different html page helloResponse.html, which displays a user-input word. Please could you help me?

Controller Code:

    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.beans.factory.annotation.Autowired;
    public class HelloController {
        private HelloService helloService;
        public String getHello() {
            return "hello";
        public String 
        postRequest(@RequestParam(name="text1",required=false)String str, Model model) {
            return "helloResponse";
        public String 
        postDbRequest(@RequestParam(name="text2")String str, Model model) {
            int id = Integer.parseInt(str);
            Employee employee = helloService.findOne(id);
            return "helloResponseDB";


    <!DOCTYPE html>
    <html xmlns_th="">
        <title>Hello World</title>
        <h1>Hello World</h1>
        <form method="post" action="/hello">
            Enter a word:
            <input type="text" name="text1 th_value="${text1_value}"/>
            <input type="submit" value="Click"/>
        <form method="post" actioin="/hello/db">
            Enter Employee's ID:
            <input type="number" name="text2" th_value="${text2_value}"/>
            <input type="submit" value="Click"/>


Comment posted by tknkrtl

theres a typo in your form html “actioin” , also how do you post requestparam ?

Comment posted by BlueSafari

I really not sure about that question bc I just write following a book…

Comment posted by BlueSafari

Thank you for the correction. I just changed as you suggested.

Comment posted by BlueSafari

Yes! It worked! Was too excited to mention it.