⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reg.jsp

📁 ssd7考试exam3,绝对有用~欢迎下载
💻 JSP
字号:
<%@ page session="true" %>
<jsp:useBean id="user" scope="page" class="" />
<%
String mesg = "";
String submit = request.getParameter("Submit");
if (submit!=null && !submit.equals("")) {
	if(user.add(request)){
		session.setAttribute("username",user.getUserName());
		session.setAttribute( "userid", Long.toString( user.getUserid() ) ); 
		response.sendRedirect("info.jsp?action=regok");
	} else if (!user.getMessage().equals("")) {
		mesg = user.getMessage();
	} else
		mesg = "注册时出现错误,请稍后再试";
}


%>



<%
public boolean add(HttpServletRequest req) throws Exception {
        if (getRequest(req)) {
            DataBase db = new DataBase();
            db.connect();
            stmt = db.conn.createStatement ();
            sqlStr = "select * from shop_user where username = '" +
                      user.getUserName() +"'";
            sqlStr = "insert into shop_user (username,password,Names,sex,"+
                     "Address,Phone,Post,Email,RegTime,RegIpaddress) values ('";
            sqlStr = sqlStr + dataFormat.toSql(user.getUserName()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getPassWord()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getNames()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getSex()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getAddress()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getPhone()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getPost()) + "','";
            sqlStr = sqlStr + dataFormat.toSql(user.getEmail()) + "',now(),'";
            sqlStr = sqlStr + user.getRegIpAddress() + "')";
            try{
                stmt.executeUpdate(sqlStr);
                sqlStr = "select max(id) from shop_user where username = '" +
                         user.getUserName()+ "'";
                         rs = stmt.executeQuery(sqlStr);
                         while (rs.next()){
                              userid = rs.getLong(1);
                              }
                             rs.close();
                             return true;
                }catch (Exception sqle){
                  System.out.print(sqle.getMessage());
                  return false;
                }
           } else{
            return false;
           }

  }

%>

<script language="javascript">

function openScript(url,name, width, height){
	var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}

function checkform() {
	if (document.form1.username.value==""){
		alert("用户名不能为空");
		document.form1.username.focus();
		return false;
	}
	if (document.form1.passwd.value==""){
		alert("用户密码不能为空");
		document.form1.passwd.focus();
		return false;
	}
	if (document.form1.passwd.value!=document.form1.passconfirm.value){
		alert("确认密码不相符!");
		document.form1.passconfirm.focus();
		return false;
	}
	
	return true;
}

</script>
<%@include file="/bookshop/inc/head.inc"%>
<form name="form1" method="post" action="reg.jsp">
  <%if (!mesg.equals("")) out.println("<p><font color=#ff0000>"+ mesg + "</font></p>");%>
    <div align="center">
    <table width="450" border="1" cellspacing="1">
      <tr> 
        <td colspan="2" align="center"><b><font color="#0000FF">用户注册</font></b></td>
      </tr>
      <tr> 
        <td width="171" align="right">用户名:</td>
        <td width="272"> 
          <input type="text" name="username" maxlength="20" size="14" >
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">密码:</td>
        <td width="272">
          <input type="password" name="passwd" maxlength="20" size="14">
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">确认密码:</td>
        <td width="272">
          <input type="password" name="passconfirm" maxlength="20" size="14">
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">真实姓名:</td>
        <td width="272">
          <input type="text" name="names" maxlength="20" size="14">
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">性别:</td>
        <td width="272">
          <select name="sex">
            <option>男</option>
            <option>女</option>
          </select>
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">联系地址:</td>
        <td width="272">
          <input type="text" name="address" maxlength="150" size="40">
        </td>
      </tr>
	  <tr> 
        <td width="171" align="right">联系邮编:</td>
        <td width="272">
          <input type="text" name="post" maxlength="8" size="8">
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">联系电话:</td>
        <td width="272">
          <input type="text" name="phone" maxlength="25" size="16">
        </td>
      </tr>
      <tr> 
        <td width="171" align="right">电子邮件:</td>
        <td width="272">
          <input type="text" name="email" maxlength="50" size="25">
        </td>
      </tr>
      <tr>
        <td width="171" align="right">&nbsp; </td>
        <td width="272">
          <input type="submit" name="Submit" value="注册" onclick="javascript:return(checkform());">
          <input type="reset" name="reset" value="取消">
        </td>
      </tr>
    </table>  
  </div>
  </form>
 
<%@include file="/bookshop/inc/tail.inc"%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -