Application Name: OpenMRS 2.3.0 with Reference Application 2.10.0
Question: I am using spring MVC. I created two request mappings in the controller for methods GET and POST. I also created a JSP file that has a form which points to the controller’s POST method. But on submitting the form, it shows 404 error with the same mapping.
My controller - NewDepartmentController is:
@Controller("departmentmodule.NewDepartmentController")
@RequestMapping("/module/departmentmodule") // parent url mapping
// some codes here ......
@RequestMapping(value = "/department.form", method = RequestMethod.GET)
public String showAddForm(Model theModel) {
Department theDepartment = new Department();
theModel.addAttribute("department", theDepartment);
return "/module/departmentmodule/department-form";
}
@RequestMapping(value = "/department.addForm", method = RequestMethod.POST)
public String submit() {
System.out.println("hihihih");
return "redirect:/module/departmentmodule/department.list";
}
department-form.jsp:
<%@ include file="/WEB-INF/template/include.jsp"%>
<%@ include file="/WEB-INF/template/header.jsp"%>
<h2>Add department form</h2>
<br/>
<form action="${pageContext.request.contextPath}/module/departmentmodule/department.addForm" method="POST">
<%-- need to associate this data with customer id --%>
<spring:bind path="department.departmentId">
<input type="hidden" name="departmentId" value="${status.value}" />
</spring:bind>
<fieldset>
<table>
<tr>
<td><openmrs:message code="general.name"/></td>
<td>
<spring:bind path="department.name">
<input type="text" name="name" value="${status.value}" size="35" />
<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
</spring:bind>
</td>
</tr>
<tr>
<td valign="top"><openmrs:message code="general.description"/></td>
<td valign="top">
<spring:bind path="department.description">
<textarea name="description" rows="3" cols="40" onkeypress="return forceMaxLength(this, 1024);" >${status.value}</textarea>
<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
</spring:bind>
</td>
</tr>
</table>
<br />
<input type="submit" value="<openmrs:message code="department.save"/>" name="save">
</fieldset>
</form>
<%@ include file="/WEB-INF/template/footer.jsp"%>
The form is:
And the result after form submit is:
Please help me to solve this issue.