2020-11-05巴本欠才让

//1、设置字符编码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
//2、获取表单数据
String username = request.getParameter("username");
String password = request.getParameter("password");
String gender = request.getParameter("gender");
//4、调用数据库的添加方法
DBUtils dbutils = new DBUtils();
int i =dbutils.save(username,password,gender);
//5、处理结果
if(i > 0) {
request.getSession().setAttribute("msg", "注册成功");
response.sendRedirect("register.jsp");
}else{
request.getSession().setAttribute("msg", "注册失败");
response.sendRedirect("register.jsp");

<!---表单
action="服务端路径"
method:提交方式(get/post)
enctype:上传文件或图片
--->

    <form action="doregister.jsp" method="post">
            用户名:<input type="text" name="username" id="username" placeholder="请输入用户名"/><br />
            密&nbsp;&nbsp;&nbsp;码:<input type="password" name="password" id="password" placeholder="请输入密码"/><br />
            性别:<input type="radio" name="gender" value="男"/>男
                 <input type="radio" name="gender" value="女"/>女<br />
            <input type="submit" value="注册">

标签

评论

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