怎样实现修改密码功能 SQL中有条语句叫 update 等你把这个弄懂了再来问吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if 你是原密码正确 update table set 密码=新密码 where 用户名=你这个够形象了吧,哈哈 <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><%@ include file="main.jsp"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>修改密码</title><link href="images/basic.css" rel="stylesheet" type="text/css" /><script language="javascript">function check(){ var oldpwd=document.form1.oldpwd.value; var newpwd=document.form1.newpwd.value; var confpwd=document.form1.confpwd.value; if(oldpwd=="") { alert("请您输入旧密码!"); document.form1.oldpwd.focus(); return false; } if(newpwd=="") { alert("请您输入新密码!"); document.form1.newpwd.focus(); return false; } if(confpwd=="") { alert("请您确认新密码!"); document.form1.confpwd.focus(); return false; } if(newpwd!=confpwd) { alert("新密码与确认密码输入不一致,请您重新输入!"); document.form1.newpwd.value=""; document.form1.confpwd.value=""; document.form1.newpwd.focus(); return false; } return true;}</script></head><body><% String sql=""; ResultSet rs=null;%><% String act=Str_rep(request.getParameter("act")); if(act.equals("ok")) { String uname=Str_rep(request.getParameter("uname")); String oldpwd=Str_rep(request.getParameter("oldpwd")); String newpwd=Str_rep(request.getParameter("newpwd")); sql="select * from users where id="+u_id+" and uname='"+uname+"' and pwd='"+oldpwd+"'"; //out.print(sql+"<br>"); rs=slink.executeQuery(sql); if(rs.next()) { sql="update users set pwd='"+newpwd+"' where id="+u_id+" and uname='"+uname+"'"; //out.print(sql+"<br>"); slink.executeUpdate(sql); session.setAttribute("pwd",newpwd); out.print("<script>alert('提示:密码修改成功!');</script>"); } else { out.print("<script>alert('警告:旧密码输入错误!');</script>"); } rs.close(); }%> <table width="560" border="0" align="center" cellpadding="2" cellspacing="1" class="table_southidc"><form id="form1" name="form1" method="post" action="?act=ok" onsubmit="return check();"> <tr> <td width="180" height="25" align="right" class="td_bgcolor1">用户名:</td> <td width="369" height="25" class="td_bgcolor1"> <input name="uname" type="text" id="uname" value="<%=u_uname%>" readonly="yes" /> </td> </tr> <tr> <td height="25" align="right" class="td_bgcolor1">旧密码:</td> <td height="25" class="td_bgcolor1"><input name="oldpwd" type="password" id="oldpwd" /> <span class="xing">*</span></td> </tr> <tr> <td height="25" align="right" class="td_bgcolor1">新密码:</td> <td height="25" class="td_bgcolor1"><input name="newpwd" type="password" id="newpwd" /> <span class="xing">*</span></td> </tr> <tr> <td height="25" align="right" class="td_bgcolor1">确认新密码:</td> <td height="25" class="td_bgcolor1"><input name="confpwd" type="password" id="confpwd" /> <span class="xing">*</span></td> </tr> <tr> <td height="25" align="right" class="td_bgcolor2"> </td> <td height="25" class="td_bgcolor2"><input type="submit" name="Submit" value="修改" /> <input type="reset" name="Submit2" value="重置" /></td> </tr></form></table><% slink.closeDB();%></body></html>参考下就知道了 struts2框架中如何查询数据库中的一条记录 Servelt和javaBean哪个功能更强大 mysql如何让front和service端连接 关于数组间赋值的问题 如何实现复选框被选中时显示一个<td></td>? ResultSet能够同时使用getXXX()和updateXXX()吗? 怎么把long转成string 阿? js时间日期相减,求帮助啊 可以将String转化为Blob类型么?在线给分 求助,Java访问Oracle数据库链接问题 使用ajax如何实现对查询结果的反红显示? 高新聘请 JSP JAVA 工程师 2名
update table set 密码=新密码 where 用户名=你
这个够形象了吧,哈哈
<%@ include file="main.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>修改密码</title>
<link href="images/basic.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function check()
{
var oldpwd=document.form1.oldpwd.value;
var newpwd=document.form1.newpwd.value;
var confpwd=document.form1.confpwd.value;
if(oldpwd=="")
{
alert("请您输入旧密码!");
document.form1.oldpwd.focus();
return false;
}
if(newpwd=="")
{
alert("请您输入新密码!");
document.form1.newpwd.focus();
return false;
}
if(confpwd=="")
{
alert("请您确认新密码!");
document.form1.confpwd.focus();
return false;
}
if(newpwd!=confpwd)
{
alert("新密码与确认密码输入不一致,请您重新输入!");
document.form1.newpwd.value="";
document.form1.confpwd.value="";
document.form1.newpwd.focus();
return false;
}
return true;
}
</script>
</head><body>
<%
String sql="";
ResultSet rs=null;
%>
<%
String act=Str_rep(request.getParameter("act"));
if(act.equals("ok"))
{
String uname=Str_rep(request.getParameter("uname"));
String oldpwd=Str_rep(request.getParameter("oldpwd"));
String newpwd=Str_rep(request.getParameter("newpwd"));
sql="select * from users where id="+u_id+" and uname='"+uname+"' and pwd='"+oldpwd+"'";
//out.print(sql+"<br>");
rs=slink.executeQuery(sql);
if(rs.next())
{
sql="update users set pwd='"+newpwd+"' where id="+u_id+" and uname='"+uname+"'";
//out.print(sql+"<br>");
slink.executeUpdate(sql);
session.setAttribute("pwd",newpwd);
out.print("<script>alert('提示:密码修改成功!');</script>");
}
else
{
out.print("<script>alert('警告:旧密码输入错误!');</script>");
}
rs.close();
}
%>
<table width="560" border="0" align="center" cellpadding="2" cellspacing="1" class="table_southidc">
<form id="form1" name="form1" method="post" action="?act=ok" onsubmit="return check();">
<tr>
<td width="180" height="25" align="right" class="td_bgcolor1">用户名:</td>
<td width="369" height="25" class="td_bgcolor1">
<input name="uname" type="text" id="uname" value="<%=u_uname%>" readonly="yes" /> </td>
</tr>
<tr>
<td height="25" align="right" class="td_bgcolor1">旧密码:</td>
<td height="25" class="td_bgcolor1"><input name="oldpwd" type="password" id="oldpwd" />
<span class="xing">*</span></td>
</tr>
<tr>
<td height="25" align="right" class="td_bgcolor1">新密码:</td>
<td height="25" class="td_bgcolor1"><input name="newpwd" type="password" id="newpwd" />
<span class="xing">*</span></td>
</tr>
<tr>
<td height="25" align="right" class="td_bgcolor1">确认新密码:</td>
<td height="25" class="td_bgcolor1"><input name="confpwd" type="password" id="confpwd" />
<span class="xing">*</span></td>
</tr>
<tr>
<td height="25" align="right" class="td_bgcolor2"> </td>
<td height="25" class="td_bgcolor2"><input type="submit" name="Submit" value="修改" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
</form>
</table>
<%
slink.closeDB();
%>
</body>
</html>
参考下就知道了