I am trying to create a jsp form for inputting the user information.
I am using a controller to display the input page.
I have added an User bean object with the modelmap.The controller returns the ModelandView object.
The problem lies here.No model value gets returned to the jsp page. Anybody know why this happens??please help me…
<context:annotation-config/>
<context:component-scan base-package="com.mobilize.rest"/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<import resource="configuration/messageConverter.xml"/>
<import resource="configuration/viewResolveContext.xml"/>
The code below shows the controller used to get the view AddUSer.jsp page
While debugging the values are properly stored in the object.
But the problem is that the object doesnt get received at the form page.
@RequestMapping(value = "/AddUser.html", method = RequestMethod.GET)
public ModelAndView addUser(
@RequestParam(value = "reload", required = false, defaultValue = "false")
Boolean reload,
@RequestParam(value = "reset", required = false, defaultValue = "false")
Boolean reset,HttpServletRequest request) {
HttpSession httpSession = request.getSession();
ModelMap modelmap = new ModelMap();
Users users = new Users();
modelmap.addAttribute("users", users);
modelmap.addAttribute("MOB_USER_ADD_STATUS_SUCCESS_MESSAGE","trial");
return new ModelAndView("AddUser", modelmap);
}
[Edited, additional code moved from comment section]
<div id="content" style="height:508px"> <br/>
<c:if test="${MOB_USER_ADD_STATUS_SUCCESS_MESSAGE!=null}">
<div align="center"
id="statusIndicator"
class="successMessage">${MOB_USER_ADD_STATUS_SUCCESS_MESSAGE}
</div>
</c:if>
${MOB_USER_ADD_STATUS_SUCCESS_MESSAGE}
<form:form commandName="users"
method="POST"
action="AddUser.html">
<table>
<tr>
<td> User Name: </td>
<td><form:input path="userName"
id="username">
</form:input>
</td>
</tr>
<tr>
<td></td>
<td><form:errors path="userName"
cssClass="errorMessage">
</form:errors>
</td>
</tr>
<tr>
<td> Password: </td>
<td> <form:textarea path="password" id="password"></form:textarea> </td>
</tr>
<tr>
<td></td>
<td><form:errors path="password" cssClass="errorMessage"></form:errors></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="offer" value=" Add "/>
<input type= "reset"
name="Reset"
value=" Reset "
onclick="document.location.href='AddUser.html?reset=true'"/>
</td>
</tr>
</table>
</form:form>
</div>
The mistake was i imported the wrong class. Instead of importing org.springframework.web.servlet.ModelAndView , i imported
org.springframework.web.portlet.ModelAndView. That was the reason for the error. I should have been a bit more careful.