In Spring MVC How to get form object in JSP from controller ? -
i trying form object in jsp controller. jsp :: updateuser.jsp
<form name="user" action="updateuser" method="post"> <ul> <li> <label>user name</label> <input type="text" name="username" /> </li> <li> <label>password</label> <input type="password" name="password" /> </li> <li> <label>firstname</label> <input type="text" name="firstname" /> </li> <li> <label>lastname</label> <input type="text" name="lastname" /> </li> </ul> <button type="submit">update</button> </form>
controller :: updateusercontroller.java
@requestmapping("/updateuser") public class updateusercontroller { @requestmapping(method = requestmethod.post) public modelandview update(@modelattribute("user") user user, modelmap model,httpservletrequest request) { return new modelandview("updateuser","user",model); } }
after adding values in field , clicking on update button. form gets submitted , in mapped pojo i'm getting value. want show values in fields without adding model object (i.e. model.addattribute("username", user.getusername()
) 1 one fields). dont want use spring tag library. how can populate values in form ??
with @modelattribute
putting user
object in model
, don't need add again returned modelandview
. model attributes added request attributes, can use el resolve them in jsp
.
<c:out value="${user.username}" />
Comments
Post a Comment