一·登录注册代码以及效果
register.jsp:注册
1 2 3 4 5 6 7 8 9 10 11 | < title >注册</ title > #a { width:50%; height:200px; border: 1px dashed ; background-color:lightyellow; text-align:center; } body{ background-color:lightblue; } |
用户名:
密码:
备注:
doregister.jsp:注册信息弹框
1 2 3 4 5 6 7 8 | 0){ out.print("alert('注册成功');location.href='login.jsp'"); }else{ out.print("alert('注册失败');location.href='register.jsp'"); } %> |
login.jsp:登录
1 2 3 4 5 6 7 8 9 10 11 | < title >登录</ title > #a { width:50%; height:200px; border: 1px dashed ; background-color:lightyellow; text-align:center; } body{ background-color:lightblue; } |
用户名:
密码:
dologin.jsp:与数据库相连、存放登陆的用户
1 2 3 4 | alert('用户名或密码错误,请重新登录');location.href='login.jsp'"); } //关闭连接 %> |
index.jsp:主界面
1 2 3 4 5 6 7 8 9 10 11 | < title >主页面</ title > #a { width:50%; height:200px; border: 1px dashed ; background-color:lightyellow; text-align:center; } body{ background-color:lightblue; } |
编号 | 用户名 | 密码 | 备注 | 操作 |
修改 详情 删除 |
update.jsp:修改
1 2 3 4 5 6 | 0){ out.print("alert('修改成功');location.href='index.jsp'"); }else{ out.print("alert('修改失败');location.href='index.jsp'"); } %> |
doup.jsp:修改页面(帮助)
1 | < title >Insert title here</ title > |
用户名:
密码:
备注:
info.jsp:详情
1 |
用户名:”>
密码:”>
备注:
返回
dodel.jsp:删除界面
1 2 3 4 5 6 | 0){ out.print("alert('删除成功');location.href='index.jsp'"); }else{ out.print("alert('删除失败');location.href='index.jsp'"); } %> |
二·页面跳转的方式以及他们的区别
1、跳转路径并传递数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | //假设法:假设我的用户名为admin 密码为123 if ( "admin" .equals(name)&& "123" .equals(pwd)){ //说明登录成功 跳转到success.jsp //1.重定向 将页面跳转 地址栏发生了改变 //不能将值传递到下一个界面 可以跳转到任意资源 在客户端发挥作用 //2.转发 将页面跳转 可以将值传递到下一个界面 //但是地址栏不发生改变 而是停留在了之前的页面 只能转发到当前项目内资源 在服务器端发挥作用 //request.getRequestDispatcher("http://www.baidu.com").forward(request, response); } else { //说明登录失败 提示用户并返回登录界面login.jsp js的跳转属于重定向 地址栏发生了改变 login-->dologin-->login out.print( "alert('用户名或者密码有误');location.href='login.jsp';" ); } |
2、页面跳转的两种方式和区别
重定向:地址栏发生改变 不能传值 可以跳转到任意资源 在客户端发挥作用
转发:地址栏不发生改变 能传值 只能跳转到当前项目内资源 在服务器端发挥作用语法:
重定向:response.sendR()转发:request.getreq .for(request,response)
三·其他
1、jdbc连接Oracle
1 | URL:jdbc:oracle:thin: @localhost : 1521 :orcl |
2、乱码
1 | request.setCharacterEncoding( "utf-8" ); |
3、添加数据时,获取最新编号
1 2 3 4 5 6 7 8 9 | //这里的代码是用来 得到最新编号的 int nextId= 1 ; //做为新用户的编号 PreparedStatement ps = con.prepareStatement( "select max(uuid) from T277" ); //执行sql语句 ResultSet rs= ps.executeQuery(); if (rs.next()){ //查询到最大的编号,加1,就是新数据的编号 nextId = rs.getInt( 1 )+ 1 ; } |
总结
到此这篇关于jsp登录注册完整实现代码的文章就介绍到这了,更多相关jsp登录注册代码内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!