注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 编程开发JSP → 文章内容

JSP用MVC架构注册登录的例子

作者:佚名 来源:不详 发布时间:2007-11-30 0:08:22

  新建用户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] 


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved