📄 list_edit.jsp
字号:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GB18030" import="java.sql.*,java.util.*,java.io.*"%>
<%@ include file="config.ini"%>
<%@ include file="conn.jsp"%>
<%@ include file="readlogin.jsp"%>
<%
//接收要修改的联系人的id
String id=request.getParameter("id");
if(id==null)
{
out.print("<script>");
out.print("alert('id错误');");
out.print("location.href='list.jsp';");
out.print("</script>");
}
%>
<%
//接收用户请求中包含的参数
String action=request.getParameter("action");
if(action==null) {action="";}
//如果请求中的参数为save,则执行数据库中更新记录的操作
if(action.equals("save"))
{
//获取用户表单提交的修改联系人的信息
String name=codeToString(request.getParameter("name"));
String sort=codeToString(request.getParameter("sort"));
String mobile=codeToString(request.getParameter("mobile"));
String home=codeToString(request.getParameter("home"));
String office=codeToString(request.getParameter("office"));
String email=codeToString(request.getParameter("email"));
String qq=codeToString(request.getParameter("qq"));
String msn=codeToString(request.getParameter("msn"));
String post=codeToString(request.getParameter("post"));
String address=codeToString(request.getParameter("address"));
String other=codeToString(request.getParameter("other"));
try
{
sqlstr="update [list] set [sort]='"+sort+"',[name]='"+name+"',[mobile]='"+mobile+"',[home]='"+home+"',[office]='"+office+"',[email]='"+email+"',[qq]='"+qq+"',[msn]='"+msn+"',[post]='"+post+"',[address]='"+address+"',[other]='"+other+"' where id="+id;
//调用JavaBean中的业务逻辑方法,进行数据库更新操作
iCanDb.doUpdate(sqlstr);
out.print("<script>");
out.print("alert('修改成功!');");
out.print("location.href='list.jsp';");
out.print("</script>");
}
catch(Exception e)
{
out.print("<script>");
out.print("alert('数据库错误!');");
out.print("location.href='list.jsp';");
out.print("</script>");
}
}
try
{
//将更新过的记录查询出来,并显示在页面中
sqlstr="select * from list where id="+id;
rs=iCanDb.doSelect(sqlstr);
if(rs.next())
{
String sort=rs.getString("sort");
String name=rs.getString("name");
String mobile=rs.getString("mobile");
if(mobile==null) mobile="";
String home=rs.getString("home");
if(home==null) home="";
String office=rs.getString("office");
if(office==null) office="";
String email=rs.getString("email");
if(email==null) email="";
String qq=rs.getString("qq");
if(qq==null) qq="";
String msn=rs.getString("msn");
if(msn==null) msn="";
String post=rs.getString("post");
if(post==null) post="";
String address=rs.getString("address");
if(address==null) address="";
String other=rs.getString("other");
if(other==null) other="";
%>
<html>
<head>
<%@ include file="head.jsp"%>
</head>
<script language="javascript">
function on_submit()
{//验证数据的合法性
if (form1.name.value == "")
{
alert("姓名不能为空");
form1.name.focus();
return false;
}
}
</script>
<body>
<center>
<table border="0" width="768" id="table1" cellspacing="0" cellpadding="0">
<tr>
<%@ include file="top.jsp"%>
</tr>
<tr>
<td width="90" valign="top">
<%@ include file="menu.jsp"%> </td>
<td width="588" valign="top">
<table border="0" width="100%" id="table3" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="1" width="100%" id="table4" bordercolorlight="#0A9EE4" cellspacing="0" cellpadding="5" bordercolordark="#0A9EE4" height=300>
<tr>
<td valign="top">
<table border="0" width="100%" id="table5" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0" width="100%" id="table6" cellspacing="0" cellpadding="0">
<tr>
<td valign="bottom" width="50%">
</td>
<td width="50%">
<img src="images/n-list.jpg" align="right" width="230" height="70"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><hr noshade color="#0A9EE4" size="1"></td>
</tr>
<tr>
<td>
<form method="POST" action="list_edit.jsp?action=save&id=<%=id%>" target=_top name="form1" onsubmit="return on_submit()">
<table border="0" width="574" id="table7" cellspacing="0" cellpadding="5">
<tr>
<td width="574" height="40">
<p align="left">
<span style="font-size: 9pt"> 姓名:<input type="text" name="name" value="<%=name%>" size="15" style="border: 1px solid #0A9EE4">
分类:<select size="1" name="sort" style="border: 1px solid #0A9EE4">
<option selected value="家人、亲戚" <%if(sort.trim().equals("家人、亲戚")) {out.print("selected");}%>>家人、亲戚
</option>
<option value="同事、同学" <%if(sort.trim().equals("同事、同学")) {out.print("selected");}%>>同事、同学</option>
<option value="朋友" <%if(sort.trim().equals("朋友")) {out.print("selected");}%>>朋友</option>
<option value="网友、笔友" <%if(sort.trim().equals("网友、笔友")) {out.print("selected");}%>>网友、笔友</option>
<option value="业务人士" <%if(sort.trim().equals("业务人士")) {out.print("selected");}%>>业务人士</option>
<option value="其他" <%if(sort.trim().equals("其他")) {out.print("selected");}%>>其他</option>
</select></span></td>
</tr>
<tr>
<td width="574" height="40">
<p align="left">
<span style="font-size: 9pt">
移动电话:<input type="text" name="mobile" size="12" style="border: 1px solid #0A9EE4" value="<%=mobile%>">
住宅电话:<input type="text" name="home" size="12" style="border: 1px solid #0A9EE4" value="<%=home%>">
办公电话:<input type="text" name="office" size="12" style="border: 1px solid #0A9EE4" value="<%=office%>"></span></td>
</tr>
<tr>
<td width="574" height="40">
<p align="left">
<span style="font-size: 9pt">
Email:<input type="text" name="email" size="14" style="border: 1px solid #0A9EE4" value="<%=email%>">
QQ:<input type="text" name="qq" size="17" style="border: 1px solid #0A9EE4" value="<%=qq%>">
MSN:<input type="text" name="msn" size="16" style="border: 1px solid #0A9EE4" value="<%=msn%>"></span></td>
</tr>
<tr>
<td width="574" height="40">
<p align="left">
<span style="font-size: 9pt">
邮编:<input type="text" name="post" size="15" style="border: 1px solid #0A9EE4" value="<%=post%>">
通讯地址:<input type="text" name="address" size="37" style="border: 1px solid #0A9EE4" value="<%=address%>"></span></td>
</tr>
<tr>
<td width="574">
<span style="font-size: 9pt">
其它:</span></td>
</tr>
<tr>
<td width="574">
<p align="center">
<span style="font-size: 9pt">
<textarea rows="8" name="other" cols="49" style="border: 1px solid #0A9EE4"><%=other%></textarea></span></td>
</tr>
<tr>
<td width="574"> </td>
</tr>
<tr>
<td width="574">
<p align="center"><input type="submit" value="提交" name="B1" style="border: 1px solid #156FC7">
<input type="button" value="返回" name="B2" style="border: 1px solid #156FC7" onclick="javascript:location.href='list.jsp';"></td>
</tr>
</table></form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="90"> </td>
</tr>
<tr>
<td width="90" valign="top">
</td>
<td width="588" valign="top">
<%@ include file="copyright.jsp"%>
</td>
<td width="90"> </td>
</tr>
</table>
<p>
</center>
</p>
</body>
</html>
<%
}
else
{
out.print("<script>");
out.print("alert('id错误!');");
out.print("location.href='list.jsp';");
out.print("</script>");
}
}
catch(Exception e)
{
out.print("<script>");
out.print("alert('数据库错误!');");
out.print("location.href='list.jsp';");
out.print("</script>");
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -