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

📄 reg.jsp

📁 机械工业出版社的《jsp2.0动态网站开发实例指南》的源代码
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="law.user" %>
<%@ page import="java.sql.*" %>
<%!
	public String codeString(String s){
		String str=s;
                try{
			byte b[]=str.getBytes("ISO-8859-1");
			str=new String (b);
			return str;
		}catch(Exception e){return str;}
	}
%>
<%!
	public String formatString(String s){
		//add format way here
		
		return s;
	}
%>
<jsp:useBean id="log" class="law.user" scope="session"/>
<html>
<head><title>reg</title></head>
<body>
<center>
<%@ include file="head.txt"%>
<%
	if(log.getLogin().equals("true")){
		if(request.getParameter("submit")!=null){
			String newpwd,newpwd2,id;
			id=request.getParameter("id");
			newpwd=request.getParameter("newpwd");
			newpwd2=request.getParameter("newpwd2");
			if(id==null)id="";
			if(newpwd==null)newpwd="";
			if(newpwd2==null)newpwd="";
			id=codeString(id);
			id=formatString(id);
			newpwd=codeString(newpwd);
			newpwd=formatString(newpwd);
			newpwd2=codeString(newpwd2);
			newpwd2=formatString(newpwd2);
			if(!newpwd.equals(newpwd2)){
				out.println("<font color=#FF0000>两次密码输入不同!");
			}
			else{
				Connection con;
				Statement sql;
				ResultSet rs;
				try{
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				      	con=DriverManager.getConnection("jdbc:odbc:law","","");
				     	sql=con.createStatement();
				      	String condition="select * from user where id='"+id+"'";
				      	rs=sql.executeQuery(condition);
				      	if(rs.next()){
				      		out.println("<font color=#FF0000>数据库中已经存在这个用户了!");
				      	}
				      	else{
				      		condition="insert into user values('"+id+"','"+newpwd+"')";
				      		sql.executeUpdate(condition);
				      		session.invalidate();
				      		out.println("注册成功!请重新登录。");
				      	}
				      	con.close();
		    		}catch(SQLException e){
		    			out.println(e);
		    		}catch(ClassNotFoundException e){
		    			out.println(e);
				}
			}	
		}
		else{
			%>
			<form action=reg.jsp method=post name=form>
			<table width=400>
			<tr>
				<td width=150>用户:</td>
				<td width=250><input type=text name=id></td>
			</tr>
			<tr>
				<td width=150>密码:</td>
				<td width=250><input type=password name=newpwd></td>
			</tr>
			<tr>
				<td width=150>密码:</td>
				<td width=250><input type=password name=newpwd2></td>
			</tr>
			</table>
			<input type=submit name=submit value=提交>
			<input type=reset name=reset value=重置>
			</form>
			<%
		}
	}
	else{
		out.print("<font color=#FF0000>您还没有登录。<br><a href='index.htm'>首页 </a>");
	}
%>
</center>
</body>
</html>

⌨️ 快捷键说明

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