I am new in spring MVC. I am taking some data from .jsp form and validating the same data from database if the data entered is already there then I want to print a message:"ALREADY PRESENT ENTER DIFFERENT DATA" otherwise "DATA ADDED SUCCESSFULLY" but on the same web page from where the user is entering the data not on a separate web page.
_____________
**form.jsp**
_____________
<html>
<head>
<meta charset="ISO-8859-1">
</head>
<body>
<form action="signup.op" method ="post">
<input type = "text" name="nm">
<input type = "password" name="pwd">
<input type = "num" name = "mobileNumber">
<input type = "submit" value="press"><br>
</form>
</body>
</html>
-----------------------------
_________________
**Controller class**
_________________
-------------------------------------------------------------------------------
**NOTE**:Before reading this code I want to clear you pople that in this Controller I am using *ModelAndView* to show the message on a separate response.jsp page but actually I don't want it.
------------------------------------------------------------------------------
@Controller
@RequestMapping("/")
public class Controller {
@Autowired
private Services services;
//constructor
public Controller() {
System.out.println(getClass().getName());
}
@RequestMapping(value="signup.op", method = RequestMethod.POST)
public ModelAndView signup( DTO dto) {
/*don't confuse from the below line of code I am just storing a String
type of value("yes" or "no") in "returnFromServices" variable and based on
this value I want to send the message(that is mentioned above) on the same
web page*/
String returnFromServices = services.saveStudentRecords(dto);
ModelAndView modelAndView = new ModelAndView("response.jsp");
if(returnFromServices.equals("yes")) {
modelAndView.addObject("message", "ALREADY PRESENT ENTER DIFFERENT DATA");
return modelAndView;
}
modelAndView.addObject("message","DATA ADDED SUCCESSFULLY" );
return modelAndView;
}
}
Use can use the ajax call to call the controller mathod in Spring MVC and use the bootstrap modal to show the response message on same page
This is the code snippet,
Ajax call
HTML code
jsp page
Modal Popup
Edit1
Controller method will be,