新建用戶newAccount.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>New Account</title> </head>
<body> <font color="#996633">創(chuàng)建新用戶 </font> <form name="form1" method="post" action="<%=response.encodeURL("new_account")%>"> <table width="75%" border="0" cellpadding="3"> <tr> <td width="42%" align="right">用戶名:</td> <td width="58%"><input type="text" name="userName"></td> </tr> <tr> <td align="right">密碼:</td> <td><input type="text" name="userPwd"></td> </tr> <tr> <td align="right">密碼問題:</td> <td><input type="text" name="hint"></td> </tr> <tr align="center"> <td colspan="2"> <input type="submit" name="Submit" value="提交"> </td> </tr> </table> </form> </body> </html>
注冊的控制器NewAccountServlet.java import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException;
import beans.LoginDB;
public class NewAccountServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ LoginDB loginDB = (LoginDB)getServletContext().getAttribute("loginDB"); LoginDB.addUser(request.getParameter("userName"), request.getParameter("userPwd"), request.getParameter("hint")); request.getRequestDispatcher(response.encodeUrl("accountCreated.jsp")).forward(request,response); } }
accountCreated.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>無標(biāo)題文檔</title> </head>
<body> 新用戶已經(jīng)創(chuàng)建! <font color="#0000FF"> <%=request.getParameter("userName")%></font> <hr><%@ include file="login_form.jsp" %> </body> </html>
出處:藍(lán)色理想
責(zé)任編輯:帥青蛙
上一頁 用MVC架構(gòu)簡單的注冊、登錄例子 [3] 下一頁
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
|