javaee(j2ee)简单注册登录系统(附详细源码)【DOC精选】Word文档下载推荐.doc
- 文档编号:468926
- 上传时间:2023-04-29
- 格式:DOC
- 页数:18
- 大小:186.50KB
javaee(j2ee)简单注册登录系统(附详细源码)【DOC精选】Word文档下载推荐.doc
《javaee(j2ee)简单注册登录系统(附详细源码)【DOC精选】Word文档下载推荐.doc》由会员分享,可在线阅读,更多相关《javaee(j2ee)简单注册登录系统(附详细源码)【DOC精选】Word文档下载推荐.doc(18页珍藏版)》请在冰点文库上搜索。
privateStringurl="
jdbc:
mysql:
//localhost:
3306/demo"
privateStringusr="
root"
privateStringpwd="
"
privateConnectionconn=null;
privateStatementstm=null;
privateResultSetrs=null;
publicStringgetDrv(){
returndrv;
}
publicvoidsetDrv(Stringdrv){
this.drv=drv;
publicStringgetUrl(){
returnurl;
publicvoidsetUrl(Stringurl){
this.url=url;
publicStringgetUsr(){
returnusr;
publicvoidsetUsr(Stringusr){
this.usr=usr;
publicStringgetPwd(){
returnpwd;
publicvoidsetPwd(Stringpwd){
this.pwd=pwd;
publicConnectiongetConn(){
returnconn;
publicvoidsetConn(Connectionconn){
this.conn=conn;
publicjava.sql.StatementgetStm(){
returnstm;
publicvoidsetStm(Statementstm){
this.stm=stm;
publicjava.sql.ResultSetgetRs(){
returnrs;
publicvoidsetRs(ResultSetrs){
this.rs=rs;
//创建数据库连接函数
publicbooleancreateConn()
{
booleanb=false;
try{
Class.forName(drv).newInstance();
conn=(Connection)DriverManager.getConnection(url,usr,pwd);
b=true;
}catch(SQLExceptione){
}catch(ClassNotFoundExceptione){
}catch(InstantiationExceptione){
}catch(IllegalAccessExceptione){
}
returnb;
//更新sql函数
publicbooleanupdate(Stringsql)
stm=(Statement)conn.createStatement();
stm.execute(sql);
}catch(Exceptione){
//查询sql函数
publicvoidquery(Stringsql)
rs=(ResultSet)stm.executeQuery(sql);
}catch(Exceptione)
{
publicbooleannext()
if(rs.next())b=true;
catch(Exceptione)
publicStringgetValue(Stringfield)
Stringvalue=null;
try{
if(rs!
=null)value=rs.getString(field);
}catch(Exceptione)
returnvalue;
publicvoidcloseRs()
if(rs!
=null)
rs.close();
catch(SQLExceptione)
{
}
publicvoidcloseStm()
stm.close();
publicvoidcloseConn()
conn.close();
}
4.UserBean.java
publicclassUserBean
{
//登录验证函数
publicbooleanvalid(Stringusername,Stringpassword)
booleanisValid=false;
DBAccessdb=newDBAccess();
if(db.createConn())
Stringsql="
select*fromuserwhereusername='
+username+"
andpassword='
+password+"
db.query(sql);
if(db.next())
isValid=true;
db.closeRs();
db.closeStm();
db.closeConn();
returnisValid;
//检查用户名是否存在
publicbooleanisExist(Stringusername)
booleanisExist=false;
if(db.createConn())
Stringsql="
db.query(sql);
if(db.next())
isExist=true;
db.closeRs();
db.closeStm();
db.closeConn();
returnisExist;
publicvoidadd(Stringusername,Stringpassword,Stringemail){
insertintouser(username,password,email)values('
'
+email+"
)"
db.update(sql);
5.login_action.jsp
<
%@pagelanguage="
java"
import="
java.util.*"
pageEncoding="
ISO-8859-1"
%>
%@pageimport="
com.demo.javabean.UserBean"
%>
%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"
:
//"
+request.getServerName()+"
+request.getServerPort()
+path+"
/"
html>
<
head>
basehref="
%=basePath%>
>
<
title>
MyJSP'
login_action.jsp'
startingpage<
/title>
/head>
body>
Stringusername=request.getParameter("
username"
Stringpassword=request.getParameter("
password"
if(username==null||password==null)
response.sendRedirect("
login.jsp"
%
//验证登录
booleanisValid=false;
UserBeanuserBean=newUserBean();
isValid=userBean.valid(username,password);
if(isValid)
session.setAttribute("
username);
welcome.jsp"
else
/body>
/html>
6.Login.jsp
utf-8"
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"
+request.getServerName()+"
+request.getServerPort()+path+"
!
DOCTYPEHTMLPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
index.jsp'
ThisismyJSPpage.<
br>
formname="
form1"
action="
login_action.jsp"
method="
post"
<
tablewidth="
200"
border="
1"
<
tr>
tdcolspan="
2"
登录窗口<
/td>
/tr>
td>
用户名<
inputtype="
text"
name="
size="
10"
密码<
inputtype="
name="
size="
tdcolspan="
submit"
value="
登录"
ahref="
register.jsp"
注册新用户<
/a>
/table>
/form>
7.Logout.jsp
logout.jsp'
<
metahttp-equiv="
pragma"
content="
no-cache"
cache-control"
expires"
0"
keywords"
keyword1,keyword2,keyword3"
description"
Thisismypage"
--
linkrel="
stylesheet"
type="
text/css"
href="
styles.css"
-->
%session.removeAttribute("
response.sendRedirect("
8.Register_action.jsp
register_action.jsp'
Stringpassword1=request.getParameter("
password1"
Stringpassword2=request.getParameter("
password2"
Stringemail=request.getParameter("
email"
//检查是否为空
if(username==null||password1==null||password2==null||!
password1.equals(password2))
//验证用户名是否存在
UserBeanuserBean=newUserBean();
booleanisExist=userBean.isExist(username);
if(!
isExist)
userBean.add(username,password1,email);
9.Register.jsp
register.jsp'
action="
register_action.jsp"
tablewidth="
注册窗口<
用户名<
确认密码<
Email<
注册"
返回<
10.welcome.jsp
Stringpath=request.getCon
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- DOC精选 javaee j2ee 简单 注册 登录 系统 详细 源码 DOC 精选