0
@RestController 
@RequestMapping(value="addPerson", method=RequestMethod.GET)
    public String addPerson(@RequestParam(value="name", required=false) String Fname, @RequestParam(value="pwd", required=false) String Lname){
        Person person= new Person(Fname,Lname);
        crudService.addPerson(person);
        return "Successfully added " + Fname;
}    
<!DOCTYPE html>
<html>

<head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
</head>

<body bgcolor="yellow">
    <form action="addPerson" method="get"></form>
    <table>
        <tr>
            <td>Enter Your Name</td>
            <td>
                <input type="text" name="name">
            </td>
        </tr>
        <tr>
            <td>Enter Password</td>
            <td>
                <input type="password" name="pwd">
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="SUBMIT">
            </td>
        </tr>
    </table>
</body>

</html>

I have placed my html file inside src/main/resources/static/NewFile.html and it's not working if I use controller like (@RequestMapping("/")) it was just returning string instead of the view.Besides that I'm giving http://localhost:80/NewFile.html to access it and in that if I enter dynamic values and submit, it doesn't go to the specific controller.

I am new to this Springboot. Can anyone please tell me where I am going wrong.

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
NaveeN
  • 121
  • 6
  • if it is hitting the API then use debugger to follow the flow and get the problem – Aman Mar 17 '17 at 09:59
  • when i try to access that api using http://localhost:80/addPerson, it gives error like this There was an unexpected error (type=Internal Server Error, status=500). ids for this class must be manually assigned before calling save(): com.gmt.crud.person.Person; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.gmt.crud.person.Person – NaveeN Mar 17 '17 at 10:23
  • But when i try to go through Html page ,enter values and hit submit it wont go to that api. It just stuck. – NaveeN Mar 17 '17 at 10:24
  • Change ->return "Successfully added " + Fname; as -> return "NewFile.html" and put your html file under webcontent folder. – Gautam Mar 17 '17 at 11:13
  • I tried it,but its not working. – NaveeN Mar 17 '17 at 11:30
  • what yon can do it to check your api and HTML page , you can check API by google extension API, so that you will know that there is no problem with API, if there is no problem in API then something is wrong in HTML part, you can google it how to use google extension Advance rest client – Aman Mar 17 '17 at 14:57
  • I am a stupid guy. I did mistake in that html page, i didn't include that text box values inside that
    .Now its working fine.
    – NaveeN Mar 18 '17 at 05:03

1 Answers1

0

Please use @Controller instead of @RestController. It'll return the view instead of string.

Kushal
  • 103
  • 1
  • 11