jsp注册页面代码
来源:互联网 发布:sql中limit的用法 编辑:程序博客网 时间:2024/05/08 18:42
用户信息的bean:
package chen;
public class UserBean
{
private String userid;
private String password;
public void setUserId(String userid)
{
this.userid=userid;
}
public void setPassword(String password)
{
this.password=password;
}
public String getUserId()
{
return this.userid;
}
public String getPassword()
{
return this.password;
}
}
提交数据库的bean:
package chen;
import com.mysql.jdbc.Driver;
import java.sql.*;
public class UserRegister
{
private UserBean userBean;
private Connection con;
//获得数据库连接。
public UserRegister()
{
String url="jdbc:mysql://localhost/"+"chao"+"?user="+"root"+"&password="+"850629";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//设置待注册的用户信息。
public void setUserBean(UserBean userBean)
{
this.userBean=userBean;
}
//进行注册
public void regist() throws Exception
{
String reg="insert into userinfo(userid,password) values(?,?)";
try
{
PreparedStatement pstmt=con.prepareStatement(reg);
pstmt.setString(1,userBean.getUserId());
pstmt.setString(2,userBean.getPassword());
pstmt.executeUpdate();
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
}
提交注册数据进入数据库:
<%@ page contentType="text/html;charset=gb2312" pageEncoding="gb2312"
import="chen.*" %>
<jsp:useBean id="userBean" class="chen.UserBean" scope="request">
<jsp:setProperty name="userBean" property="*"/>
</jsp:useBean>
<jsp:useBean id="regist" class="chen.UserRegister" scope="request"/>
<html>
<head>
<title> 用户信息注册页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
String userid =request.getParameter("userid");
String password = request.getParameter("password");
userBean.setUserId(userid);
userBean.setPassword(password);
System.out.println(userid+password);
%>
<% try{
regist.setUserBean(userBean);
out.println(userid);
regist.regist();
out.println("注册成功");}
catch(Exception e){
out.println(e.getMessage());
}
%>
<br>
<a href="login.jsp">返回</a>
</body>
</html>
登陆验证页面:
< import="java.sql.*" contentType="text/html;charset=GB2312" %>
< import="java.util.*"%>
<%
String userid1=new String(request.getParameter("userid"));
String password1=new String(request.getParameter("password"));
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/chao","root","850629");
Statement stmt=con.createStatement();
String sql="select * from userinfo where userid='"+userid1+"';";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{String password=new String(rs.getString("password"));
if(password.equals(password1))
{session.setAttribute("userid1",userid1);
response.sendRedirect("sucess.jsp");
}
else
{response.sendRedirect("login.jsp");
}
}
else
{response.sendRedirect("login.jsp");
}
%>
登陆页面:
<%@ page contentType="text/html; charset=gb2312" %>
<html>
<body>
<form method="get" action="checklogin.jsp">
<table>
<tr><td> 输入用户名:</td>
<td><input type=text name=userid ></td>
</tr>
<tr><td>输入密码:</td>
<td><input type=password name=password></td>
</tr>
<tr><td><input type=submit value=确认>
</td></tr>
</table>
</form>
<form action="register.jsp">
<input type=submit value=注册>
</form>
</body>
</html>
注册页面:
< contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.io.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<center>
<h1>注册新用户</h1>
<form action="adduser.jsp" method=post>
<table border="1" bgcolor="#0099CC">
<tr>
<td> 用户名:
<input type="text" name="userid">
</td>
</tr>
<tr valign="middle">
<td> 密码:
<input type="password" name="password" readonly>
</td>
</tr>
<tr>
<td>
<input type=submit value=提交>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
登陆成功页面:
< import="java.util.*" contentType="text/html; charset=gb2312" %>
< file="trans.jsp"%>
<html>
<head>
<title>
sucess
</title>
</head>
<body bgcolor="#ffffff">
<h1>
登录成功,欢迎您!
</h1><%=trans(session.getAttribute("userid1"))%>
</body>
</html>
- jsp注册页面代码
- JSP注册页面
- jsp中的注册代码
- HTML注册页面代码
- asp注册页面代码
- 注册页面代码
- 注册页面代码
- HTML注册页面代码
- .NET注册页面代码
- jsp注册页面,全解
- Jsp页面注册与登录
- 用jsp写注册页面
- 典型注册页面JSP实现
- Jsp页面注册与登录
- JSP用户注册登陆注销JSP页面
- JSP用户注册登陆注销JSP页面
- JSP用户注册登陆注销JSP页面
- jsp页面返回代码
- UVA 11609 - Teams(数论+推理+快速幂)
- 为什么匿名内部类只能访问其所在方法中的final变量
- STL 之随机访问迭代器
- 最大报销额 + 0-1背包
- 在TextView中设置超链接、字体、颜色
- jsp注册页面代码
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
- 微软2014实习生及秋令营技术类职位在线测试第3题
- Java中hashCode的作用
- Ubuntu下搭建Android Eclipse开发环境
- 2014浙江省赛总结
- UIButton设置为disabled且不变灰的解决方法
- 解决Android手机 屏幕横竖屏切换
- 安装编译环境