点击用户信息修改的时候,我们希望该账号信息可以显示出来,给用户更好的使用体验
因此,点击用户信息修改时,我们先不跳转到modifyuserinfo.jsp,而是根据页面的账号id查找该用户信息,传到修改页面,如下:
//servlet层代码
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String id = req.getParameter("id");
List<User> userList = service.findUserById(id);
req.setAttribute("user", userList.get(0));
req.getRequestDispatcher("/modifyuserinfo.jsp").forward(req, resp);
}
modifyuserinfo.jsp
<form action="${PageContext.request.contextPath }/bookStore/servlet/modifyUserInfoServlet?id=${user.id}" method="post" style="width: 50%;
background-color: ghostwhite;border: double;">
<h1>修改信息</h1>
<table>
<tr>
<td >姓名</td>
<td><input type="text" name="name" value="${user.name }"/></td>
</tr>
<tr>
<td >会员邮箱</td>
<td><input type="text" name="mailBox" value="${user.mailBox }"/></td>
</tr>
<tr>
<td >年龄</td>
<td><input type="text" name="age" value="${user.age }"/></td>
</tr>
<tr>
<td >密码</td>
<td><input type="password" name="password" value="${user.password }"/></td>
</tr>
<tr>
<td >重复密码</td>
<td><input type="password" name="repeatpassword" value="${user.password }"/></td>
</tr>
<tr>
<td >性别</td>
<td>
男<input name="sex" type="radio" value="male" ${user.sex.equals('male')? "checked='checked'":"''"}/>
女<input name="sex" type="radio" value="female"/>
</td>
</tr>
<tr>
<td >联系电话</td>
<td><input type="text" name="tel" value="${user.tel }"/></td>
</tr>
<tr>
<td >个人介绍</td>
<td ><textarea cols="22" rows="3" name="intro">${user.intro }</textarea></td>
</tr>
</table>
<hr/>
<input type="submit" value="提交"><br><br>
</form>
servlet传来的user,可直接用el表达式${user.id }显示