📄 registerlogic.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册</title>
</head>
<body>
<%request.setCharacterEncoding("gb2312");%>
<%
try{
String username=request.getParameter("Username");
String password=request.getParameter("Password");
String passwordagain=request.getParameter("Passwordagain");
String userkinds=request.getParameter("userkinds");
String e_mail=request.getParameter("EMail");
if(e_mail.equals("")){
e_mail="no email address";
}
if(password.equals("")||passwordagain.equals("")||!password.equals(passwordagain)){
else if(userkinds.trim().equals(""))out.print("<script>alert('密码输入不正确!');</script>");
String redirctURL="register.jsp";
response.sendRedirect(response.encodeURL(redirctURL));
}
else if(username.equals(""))out.print("<script>alert('请输入用户名!');window.location.href='register.jsp'</script>");
else if(userkinds.trim().equals(""))out.print("<script>alert('请选择用户类型!');window.location.href='register.jsp'</script>");
else{
String sqlquerystring="SELECT Username FROM logstu";
sqlquerystring+=" "+"WHERE Username LIKE"+""+"'"+username+"'";
String driver= "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
String ConURL = "jdbc:odbc:login";
Connection con = null;
con = DriverManager.getConnection(ConURL,"sa","453558337");
Statement stmt = con.createStatement();
ResultSet rs = null;
/*String s="CREATE TABLE logstu("
+"username VARCHAR(16),";
+"password VARCHAR(16),";
+"passwordagain VARCHAR(16),";
+"e_mail VARCHAR(16);"");";
try{
stmt.execute(s);
}catch(Exception e){
out.print("Problems with create SQL table: "+e.getMessage());
return;
}
out.print("you hava create a table"); */
rs = stmt.executeQuery(sqlquerystring);
if(rs.next()){
if(rs.getString(1).trim().equals(username.trim()))out.print("<script>alert('ó??§??ò?′??ú£???ê?è?D?μ?ó??§??');window.location.href='register.html'</script>");
else{
String redirectURL="register.jsp";
response.sendRedirect(response.encodeURL(redirectURL));
}
rs.close();
stmt.close();
con.close();
}
else{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
sqlquerystring="SELECT * FROM logstu";
rs=stmt.executeQuery(sqlquerystring);
rs.last();
rs.updateString(1,username);
rs.updateString(2,password);
rs.updateString(3,passwordagain);
rs.updateString(4,userkinds);
rs.updateString(5,e_mail);
rs.insertRow();
SQLWarning warn=rs.getWarnings();
if(warn!=null){
out.println("---------------Warning-----------");
out.println("<br>");
while(warn!=null){
out.println("Message:"+warn.getMessage());
out.println("<br>");
out.println("SQLState:"+warn.getSQLState());
out.println("<br>");
out.println("Vendor error code:");
out.println("<br>");
warn=warn.getNextWarning();
}
}
rs.close();
stmt.close();
con.close();
String redirectURL="login.jsp";
response.sendRedirect(response.encodeURL(redirectURL));
}
}
}
catch(SQLException ex) {
out.println("SQLException caught");
out.println("<br>");
while(ex!=null){
out.println("Message:"+ex.getMessage());
out.println("<br>");
out.println("SQLState:"+ex.getSQLState());
out.println("<br>");
out.println("ErrorCode:"+ex.getErrorCode());
out.println("<br>");
ex=ex.getNextException();
}
}
%>
</html>
</body>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -