开发者学堂课程【Java Web 项目实战1:注册登录、客户关系管理系统:regist.jsp页面回显,注册基本完成】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/39/detail/903
regist.jsp页面回显,注册基本完成
<body> <h1>注册</h1> <p style="color: red; font-weight: 900">$ {msg )</p> <%--${pageContext.request.contextPath }/RegistServlet --%> <form action="<c:url value= '/RegistServlet'/>" method="post"> 用户名:<input type="text" name="username" value="${user.username }"/><br/> 密码:Rinput type="lpassvord" name="“password" value="$ {user.password } "/><br/> <input type="submit" value="注鹖"/> </form> </ body> </ ntml> |
User form = CommonUtils.toBean(request.getParametezMap(),User.class); /* * 2.调用userService的regist ()方法,传递form过去 * 3.得到异常:获取异常信息,保存到request域,转发到regist.jsp中显示 * 4.没有异常:输出注册成功! * / try { userservice.regist (form) ; response. getwriter( ).print ( "<h1>汪册成功!</h1<a href='" + request.getContextPath () + " / user/ login.jsp" +">点击这里去登录</ a>"); }catch (UserException e)i //获取异常信息,保存到request域 request.setAttribute ( "msg" , e.getMessage () ); /还要保存表单数据,到requestt域 request.setkttribute ( "user" , form); //用来在表单中回显! //转发到regist.jsp request.getRequestDispatcher ("/user/regist.jsp").forward(request,response); } } |