• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
柘冉
博客园    首页    新随笔    联系   管理    订阅  订阅
作业
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>

  <body>
    <form name="form1" method="post" action="control.jsp" >
        <table>
        <tr>
            <td>编号:</td>
                <td> <input type="text" name="sid" id="userName"  ></td>
            </tr>
            <tr>
                <td>用户名:</td>
                <td> <input type="text" name="uname" id="userName"  ></td>
            </tr>
            <tr>
                 <td>输入登录密码:</td>
                <td><input type="password" name="upwd" id="pwd"></td>
            </tr>

            <tr>
                <td colspan="2"><input type="submit" value="注册"></td>
            </tr>
        </table>
    </form>
  </body>
</html>

  

public static int insertuser(String username, String password,String realname) {
        Connection conn = null;
        PreparedStatement ps = null;
        int count = 0;
        try {
            //获取连接
            conn = DBUtils.getConnection();
            //获取预编译的数据库操作对象
            String sql = "insert into t_users (login_name,login_pwd,real_name) values (?,?,?)";

            ps = conn.prepareStatement(sql);
            //传值
            ps.setString(1, username);
            ps.setString(2, password);
            ps.setString(3,realname);
            count = ps.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DBUtils.close(conn, ps, null);
        }
        return count;
    }

 

<%@page import="com.ee.dao.UserDao"%>
<%@page import="com.ee.bean.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    User u = new User();
    
    String uname = request.getParameter("name");
    u.setUname(uname);
    String upwd = request.getParameter("password");
    u.setUpwd(upwd);
    UserDao ud=new UserDao();
    if(ud.addUser(u)>0){
        //跳转注册成功页面 
    }else{
        //错误页面 
    }    
%>
<%    
    if(uname.equals("zs")&&upwd.equals("123")){
    //跳转成功登录页面
    request.getRequestDispatcher("welcome.jsp").forward(request, response);
    session.setAttribute("name",name);
    }
    else{
    //错误页面
    request.getRequestDispatcher("login.jsp").forward(request, response);
    }
%>

  

 

posted on 2021-04-19 17:34  柘冉  阅读(55)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3