script心得,哈哈。。。

 

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <%@page import = "loss.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" type="text/css" href="./lib/ext-3.3.1/resources/css/ext-all.css" mce_href="lib/ext-3.3.1/resources/css/ext-all.css" /> <mce:script type="text/javascript" src="lib/ext-3.3.1/adapter/ext/ext-base.js" mce_src="lib/ext-3.3.1/adapter/ext/ext-base.js"><!-- // --></mce:script> <mce:script type="text/javascript" src="lib/ext-3.3.1/ext-all-debug.js" mce_src="lib/ext-3.3.1/ext-all-debug.js"><!-- // --></mce:script> <title>修改密码</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css"> --> <%! String Password = "222123"; String Log_Username = "091110301"; //E:/workspace/card/src/loss/modify.java ? method = Modify <form name = "form1" ID = "form1" action = "modifyPassword.jsp" method = "post" name = "listen1" > //src/loss/modify.java %> <% boolean result = false; modify.setLog_Username(Log_Username); String pass = request.getParameter("password_new_Sure"); if(null != pass) { modify.setPassword(pass); System.out.println(pass + " 新密码"); result = modify.Modify(); } if(result == true){ // response.getWriter().print("<javascript type='text/javascript'>alert('密码');</javascript>"); out.print("<mce:script type='text/javascript'><!-- alert('密码'); // --></mce:script>"); } else if ( result == false && (null != pass) ){ out.print("<mce:script type='text/javascript'><!-- alert('密码'); // --></mce:script>"); // response.getWriter().print("<javascript type='text/javascript'>alert('密码');</javascript>"); } %> </head> <body BACKGROUND = "image/wenli.jpg"> <form name = "form1" ID = "form1" action = "modifyPassword.jsp" method = "post" name = "listen1" > 选择账号: <select id = "ID" name = "ID"> <option value = "0"><%=Log_Username%></option> </select> <br></br> <mce:script language="javascript"><!-- function Check() { var password = document.form1.password.value;//输入原密码获得 if(password.length!=6) { alert('密码要求为六位..'); } else{ var password_pre = <%=Password%>; if(password == password_pre){//是否匹配 } else{ alert('密码错误!!!请重新输入.'); document.form1.password.value = null; } } } // --></mce:script> 原密码 : <input type= "password" name = "password" onblur= "Check();" name = "listen"/><br></br> <mce:script language = "javascript"><!-- function Check_new_bits(){ password_new = document.form1.password_new.value; if(password_new.length!=6) { alert('密码要求为六位..'); } else{ ;//kong } } // --></mce:script> 新密码 : <input type = "password" name = "password_new" onblur = "Check_new_bits();"><br></br> <mce:script language="javascript"><!-- function CheckTOO(){ var password_new_Sure = document.form1.password_new_Sure.value; var password_new = document.form1.password_new.value; if(password_new_Sure == password_new){ <%System.out.println("确认成功。。");%> ; } else{ alert("密码错误!!!请重新输入."); document.form1.password_new_Sure = null; } } // --></mce:script> 新查询密<br></br> 码确认 : <input type = "password" name = "password_new_Sure" onblur = "CheckTOO();"><br></br> <mce:script language="javascript"><!-- function end(){ } // --></mce:script> <button type = "submit" name = "submit" >确定</button> </form> </body> </html> 

已上是课设的modifyPassword.jsp页面;以上是可执行的简单密码更改的操作;
有以下几点收获:
1.在jsp的java代码块是在页面加载时就已经执行的;对于那些镶嵌在script标签里的function函数,也一样,未触发事件也会在页面加载时执行一次;当在html或script里的各个时间调用时,也会执行;
2.对于response和request的操作,必须是页面提交后草可以使用;jsp页面调用其他的jsp页面,则用responde.getparameter("name");name是属性名;
3.对于自己页面的java代码块掉用自己页面的各种标签所对应的值,则是整个页面提交之后,才可获取;
比如说如下代码:
<mce:script language="javascript"><!-- function end(){ <% boolean result = false; modify.setLog_Username(Log_Username); String pass = request.getParameter("password_new_Sure"); if(null != pass) { modify.setPassword(pass); System.out.println(pass + " 新密码"); result = modify.Modify(); } if(result == true){ %> alert('密码更新成功。。。'); <%} else if ( result == false && (null != pass) ){ %> alert('密码更新失败。。。'); <% } %> } // --></mce:script> <button type = "submit" name = "submit" onclick = "end();">确定</button> 
里面的
String pass = request.getParameter("password_new_Sure");
password_new_Sure是form里的密码矿的name属性;
点击button是先触发事件end();但是事件表单password_new_Sure得值不能获取;该值必须是在submit执行提交之后才执行;
所以导致我出现alert框弹出"密码更新失败";但是数据库里的密码还是更新成功了;
该操作就是因为调用end();函数时respond没有执行;而是在submit之后执行的;

 

你可能感兴趣的:(script心得,哈哈。。。)