新建用户newAccount.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Account</title>
</head>
<body>
<font color="#996633">创建新用户 </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>无标题文档</title>
</head>
<body>
新用户已经创建! <font color="#0000FF">
<%=request.getParameter("userName")%></font>
<hr><%@ include file="login_form.jsp" %>
</body>
</html>
上一页 [1] [2] [3] [4]