用户注册功能

> 2.完成用户注册功能 [1]    package com.itheima_regist;
> 
> public class User {   private int id;     private String username;
>   private String password;    private String email;   private String name;
>   private String sex;     private String telephone;   public int getId() {
>       return id;  }   public void setId(int id) {         this.id = id;   }
>   public String getUsername() {       return username;    }   public void
> setUsername(String username) {        this.username = username;   }   public
> String getPassword() {        return password;    }   public void
> setPassword(String password) {        this.password = password;   }   public
> String getEmail() {       return email;   }   public void setEmail(String
> email) {      this.email = email;     }   public String getName() {       return
> name;     }   public void setName(String name) {      this.name = name;   }
>   public String getSex() {        return sex;     }   public void setSex(String
> sex) {        this.sex = sex;     }   public String getTelephone() {      return
> telephone;    }   public void setTelephone(String telephone) {
>       this.telephone = telephone;     }    }
> 
> [2]   package com.itheima_regist;
> 
> import java.io.IOException;
> 
> import javax.servlet.ServletException; import
> javax.servlet.http.HttpServlet; import
> javax.servlet.http.HttpServletRequest; import
> javax.servlet.http.HttpServletResponse; /*  *完成用户注册的功能   */ public
> class RegistServlet extends HttpServlet {     private static final long
> serialVersionUID = 1L;
> 
>   protected void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {      try {
>           request.setCharacterEncoding("utf-8");      //接收参数      String username =
> request.getParameter("username");         String password =
> request.getParameter("password");         String email =
> request.getParameter("email");        String name =
> request.getParameter("name");         String sex =
> request.getParameter("sex");      String telephone =
> request.getParameter("telephone");        //封装数据      User user = new User();
>       user.setUsername(username);         user.setPassword(password);
>       user.setEmail(email);       user.setName(name);         user.setSex(sex);
>       user.setTelephone(telephone);       //调用业务层处理数据         UserService
> userservice = new UserService();      userservice.regist(user);       //页面跳转
>       response.sendRedirect("/day15/demo2-regist/index.html");        } catch
> (Exception e) {           e.printStackTrace();        }   }   protected void
> doPost(HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException {        doGet(request,response);    }
> 
> }
> 
> [3]   package com.itheima_regist;
> 
> public class UserService {
> 
>   public void regist(User user) throws Exception {        UserDao userDao =
> new UserDao();        userDao.regist(user);
>           }
> 
> }
> 
> [4]   public class UserDao { /*  *Dao中用户注册的方法   */    public void
> regist(User user) throws Exception {      QueryRunner queryRunner = new
> QueryRunner(JDBCUtils.getDataSource());       String sql = "insert into
> login values(null,?,?,?,?,?,?)";      Object[]
> objects={user.getUsername(),user.getPassword(),user.getEmail(),user.getUsername(),user.getSex(),user.getTelephone()};
>       queryRunner.update(sql, objects);   }
> 
> }
> 
> [5] 
>     
>     RegistServlet
>     RegistServlet
>     class>com.itheima_regist.RegistServletclass>      
>     RegistServlet
>     /RegistServlet       [6]     
class="form-horizontal" style="margin-top:5px;" > action="/day15/RegistServlet" method="post"> >
class="form-group"> > >
class="col-sm-6"> > "text" class="form-control" name="username" placeholder="请输入用户名"> >
>
>
class="form-group"> > >
class="col-sm-6"> > "password" class="form-control" name="password" placeholder="请输入密码"> >
>
>
class="form-group"> > >
class="col-sm-6"> > "password" class="form-control" name="repassword" placeholder="请输入确认密码"> >
>
>
class="form-group"> > >
class="col-sm-6"> > "text" class="form-control" name="email" placeholder="Email"> >
>
>
class="form-group"> > >
class="col-sm-6"> > "text" class="form-control" name="name" placeholder="请输入姓名"> >
>
>
class="form-group opt"> > >
class="col-sm-6"> >
>
>
class="form-group"> > >
class="col-sm-6"> > "text" class="form-control" name="telephone" > >
>

你可能感兴趣的:(java,用户注册)