i have a controller that has a role to add the customer to my list and i have two methods showFormForAdd()
to take a parameter and saveCustomer()
for saving a customer and comeback to the list page and i have a parent request mapping named /c
. the problem is that when i click on my submit button it duplicate the mapping url like this /c/customer/c/customer/savecustomer
and i am unable to save my customer.i found out it works fine if i change action="c/customer/savecustomer"
to action="savecustomer"
but i have no idea why and what was wrong with that in the first place.i am using jsp and spring 5 mvc.
contoller
@Controller
@RequestMapping("/c")
public class CustomerController {
@GetMapping("/customer/showFormForAdd")
public String showFormForAdd(Model themodel){
Customer thecustomer=new Customer();
themodel.addAttribute("customer",thecustomer);
return "customer-form";
}
@PostMapping("/customer/savecustomer")
public String saveCustomer(@ModelAttribute("customer") Customer thecustomer){
customerService.saveCustomer(thecustomer);
return "redirect:/c/customer/list";
}
}
jsp page
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/style.css"/>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/add-customer-style.css"/>
</head>
<body>
<div id="wrapper">
<div id="header">
<h2>CRM CUSOMER MANAGER</h2>
</div>
</div>
<div id="container">
<%-- <form:form action="/customer/savecustomer" --%>
<form:form action="c/customer/savecustomer" modelAttribute="customer" method="post" >
<form:hidden path="id"/>
<table>
<tbody>
<tr>
<td><label>First Name</label></td>
<td><form:input path="firstName"/></td>
</tr>
<tr>
<td><label>last Name</label></td>
<td><form:input path="lastName"/></td>
</tr>
<tr>
<td><label>email </label></td>
<td><form:input path="email"/></td>
</tr>
<tr>
<td><label> </label></td>
<td><input type="submit" value="save" class="save"></td>
</tr>
</tbody>
</table>
</form:form>
<div style="clear: both"></div>
<p>
<a href="${pageContext.request.contextPath}/customer/list">
back to the form </a>
</p>
</div>
</body>
</html>
log
31-Jul-2020 09:42:23.928 WARNING [http-nio-8080-exec-4] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/javacongif_war/] in DispatcherServlet with name 'dispatcher'