2020-11-05马海平

课堂笔记: 注册页面

request.setCharacterEncoding("UTF-8");
         response.setCharacterEncoding("UTF-8")
         String username = request.getParameter("username");
         String password = request.getParameter("password");
         String gender = request.getParameter("gender");
         DBHelper dbhelper = new DBHelper();
         int i =dbhelper.save(username,password,gender);
         if(i > 0) {
         request.getSession().setAttribute("msg","注册成功");
         response.sendRedirect("denglu.jsp");
         }else{
      request.getSession().setAttribute("msg","注册失败");
       response.sendRedirect("denglu.jsp");
     }
rejiester.jsp文件的建立
<%@ page language="java" contentType="text/html; charset=UTF-8"
<form action="dorejiester.jsp" method=" post" >
用户名:<input type="text" name="username" placeholder="请输入用户名" />
密&nbsp;码:<input type="password" name="password" placeholder="请输入密码"/>
性别:<input type="radio" name="gender" value="男"/>男
<input type="submit" value="注册" />

public int save(String userName,String passWord,String gender ) throws Exception {
//1加载数据库驱动
Class.forName("com.mysql.jdbc.Driver");
//2创建数据库链接
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_user","root","");
//3拼写sql语句
String sql = "INSERT INTO t_user (userName,`passWord`,gender)VALUES(?,?,?)";

心得体会:今天老师给我们讲述了一些知识,学习到了许多以前没学过的专业知识与知识的应用,我们应该牢记必须刻苦努力加强记忆,时时刻刻
都得加强练习。

标签

评论

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1