书签 分享 收藏 举报 版权申诉 / 29

类型实验6.docx

  • 文档编号:9529514
  • 上传时间:2023-02-05
  • 格式:DOCX
  • 页数:29
  • 大小:496.73KB

4密码检查checklog.jsp

<%@pagecontentType="text/html"pageEncoding="gb2312"%>

<%@pageimport="java.sql.*"%>

验证用户登录

<%

request.setCharacterEncoding("gb2312");//设置请求信息使用的字符集

%>

useBeanid="db"class="ch09.DoDB"/>

useBeanid="user"scope="session"class="ch09.UserCheck"/>

setPropertyname="user"property="*"/>

<%--user保存用户登录信息,注意jsp:

setProperty用*代替属性名,

--这样可自动用同名参数给属性赋值。

--user对象的作用范围为session,即在整个会话期间都有效。

--%>

<%

if(user.getUserName()!

=""){

Stringsql="select*fromadminswhereusername='"+user.getUserName()

+"'andpassword='"+user.getUserPassword()+"'";

ResultSetrs=db.doQuery(sql);//查询用户名和口令

if(rs.next()){//如果有返回记录,说明用户名和口令正确

user.setPassed(true);//设置登录标识

response.sendRedirect("viewdata.jsp");//跳转到数据显示页面

}else{//用户名和口令不正确,输入提示信息。

out.println("用户名或口令不正确,请重新登录!


");

}

}

db.close();

%>

用户名:

value="

getPropertyname='user'property='userName'/>"size="20"/>


 

口令:

value="

getPropertyname='user'property='userPassword'/>"size="21"/>

functionNoSpace(){

if(document.all.userName.value==""){

alert("用户名不能为空!

");

returnfalse;

}

if(document.all.userPassword.value==""){

alert("口令不能为空");

returnfalse;

}

returntrue;

}

5、显示系统用户信息网页viewdata.jsp

<%@pagecontentType="text/html"pageEncoding="gb2312"%>

<%@pageimport="java.sql.*"%>

useBeanid="db"class="ch09.DoDB"/>

useBeanid="user"scope="session"class="ch09.UserCheck"/>

管理数据库

<%

response.setHeader("Expires","0");

if(!

user.isPassed()){

//如果用户没有登录,跳转到登录页面

response.sendRedirect("http:

//localhost:

8080/ch09");

}

ResultSetrs=db.doQuery("select*fromadmins");//返回数据库用户信息

out.println("当前系统用户信息如下:


");

out.println("");

out.println("用户名口令编辑删除");

out.println("");

Stringun,pwd,str;

while(rs.next()){

un=rs.getString("username");

pwd=rs.getString("password");

out.println("");

out.println(un);

out.println("");

out.println(pwd);

out.println("");

str="

username="+un+"&password="+pwd+">编辑";

out.println(str);

out.println("");

//str="";

str="

username="+un+">删除";

out.println(str);

out.println("");

}

out.println("");

db.close();

%>


添加记录

6、删除用户的网页deletedata.jsp

<%@pagecontentType="text/html"pageEncoding="gb2312"%>

<%@pageimport="java.sql.*"%>

删除记录

useBeanid="db"class="ch09.DoDB"/>

useBeanid="user"scope="session"class="ch09.UserCheck"/>

<%

if(!

user.isPassed()){

//如果用户没有登录,跳转到登录页面

response.sendRedirect("http:

//localhost:

8080/chapter04BeanDB/");

}

request.setCharacterEncoding("gb2312");

Stringsql="deletefromadminswhereusername='"+request.getParameter("username")+"'";

Stringrel=db.doUpdate(sql);

db.close();

if(rel.isEmpty())

//db.doUpdate方法返回空字符串说明更新操作成功完成

response.sendRedirect("viewdata.jsp");

else

out.println("无法将数据存入数据库:

"+rel);//操作无法完成,输出出错信息

%>

7、修改用户信息的网页editdata.jsp

<%@pagecontentType="text/html"pageEncoding="gb2312"%>

<%@pageimport="java.sql.*"%>

修改记录

useBeanid="user"scope="session"class="ch09.UserCheck"/>

<%

if(!

user.isPassed()){

//如果用户没有登录,跳转到登录页面

response.sendRedirect("http:

//localhost:

8080/chapter04BeanDB/");

}

request.setCharacterEncoding("gb2312");

%>

用户名:

value="<%=request.getParameter("username")%>"size="20"/>


 

口令:

value="<%=request.getParameter("password")%>"size="21"/>

value="<%=request.getParameter("username")%>"/>

 

packageaaaaaa;

importjava.sql.*;

publicclassDoDB{

ConnectionCn;//连接对象,用于建立和管理数据库连接

StatementSt;//语句对象,用于执行SQL命令,完成数据库操作

ResultSetRs;//记录集对象,用于保存查询结果

publicDoDB(){//初始化数据库操作对象

try{

Stringurl="jdbc:

sqlserver:

//localhost:

1433;user=sa1;password=123";

Cn=DriverManager.getConnection(url);

this.St=this.Cn.createStatement();

this.Rs=null;

}catch(Exceptionex){

ex.printStackTrace();

}

}

publicStringdoUpdate(Stringsql){//执行SQL添加、删除和修改等更新命令

try{

this.St.executeUpdate(sql);

return"";

}catch(Exceptionex){

ex.printStackTrace();

returnex.getMessage();

}

}

publicResultSetdoQuery(Stringsql){//执行SQL查询命令,返回查询结果

try{

this.Rs=this.St.executeQuery(sql);

}catch(Exceptionex){

ex.printStackTrace();

}

returnthis.Rs;

}

publicvoidclose(){//执行清理操作

try{

if(!

this.Rs.wasNull()){

this.Rs.close();

this.Rs=null;

}

if(!

this.St.isClosed()){

this.St.close();

this.St=null;

}

if(!

this.Cn.isClosed()){

this.Cn.close();

this.Cn=null;

}

}catch(Exceptionex){

ex.printStackTrace();

}

}

}

 

packageaaaaaa;

publicclassUserCheck{

StringuserName="";//存储用户名

StringuserPassword="";//存储口令

booleanpassed=false;//存储用户是否通过登录验证

publicbooleanisPassed(){

returnpassed;

}

publicvoidsetPassed(booleanpassed){

this.passed=passed;

}

publicStringgetUserName(){

returnuserName;

}

publicvoidsetUserName(StringuserName){

this.userName=userName;

}

publicStringgetUserPassword(){

returnuserPassword;

}

publicvoidsetUserPassword(StringuserPassword){

this.userPassword=userPassword;

}

}

 

<%@pagecontentType="text/html"pageEncoding="gb2312"%>

用户登录

functionNoSpace(){

if(document.all.userName.value==""){

alert("用户名不能为空!

");

returnfalse;

}

if(document.all.userPassword.value==""){

alert("口令不能为空");

returnfalse;

}

returntrue;

}

配套讲稿:

如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

特殊限制:

部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

关 键  词:
实验
提示  冰豆网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:实验6.docx
链接地址:https://www.bdocx.com/doc/9529514.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2008-2022 冰点文档网站版权所有

经营许可证编号:鄂ICP备2022015515号-1

收起
展开