本系列博客汇总在这里:企业信息管理系统汇总


用户预更新

新建 toUpdate.jsp 文件

我们需要修改数据,首先需要将数据读取出来,源码见附件一。
企业信息管理系统(7)_用户预更新_java

效果图

在首页点击编辑以后,发现数据被读取出来,此时我们可以对数据进行修改了。对于修改提交的部分见下讲。
企业信息管理系统(7)_用户预更新_数据_02

附件

附件一

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="com.wyx.ces.*" %>
<%@page import="com.wyx.ces.model.*" %>
<%@page import="java.math.BigDecimal"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">

a 
{
	text-decoration: none;
}

body
{
	font-size:12px; 
	color: #033D61;
}


.tableb 
{
	border-collapse: collapse;
	width: 60%;
}


.tableb th, .tableb td
{
	border: 1px solid #33A9D0;
	height: 20px;
}
th
{
	background-color: #E7F2FA;
}
</style>

</head>

<body>
<span>当前位置:用户管理>>用户添加</span>
<hr>

<%
	String uesrIdStr = request.getParameter("userId");
	Integer userId = null;
	if(uesrIdStr != null)
	{
		userId = new Integer(uesrIdStr);
	}
	PreparedStatement pstmt = null;
	String sql = "select * from cs_user where user_id = ?";
	ResultSet rs = null;
	CSUsr user = new CSUsr();
	try
	{
		pstmt = DBUtil.getPstmt(sql);
		pstmt.setInt(1,userId);
		rs = pstmt.executeQuery();
		rs.next();
		String username = rs.getString("username");
		String password = rs.getString("password");
		Integer gender = rs.getInt("gender");
		java.util.Date birthday = rs.getDate("birthday");
		String address = rs.getString("address");
		BigDecimal sal = rs.getBigDecimal("sal");
		
		user.setUserId(userId);
		user.setUsername(username);
		user.setPassword(password);
		user.setBirthday(birthday);
		user.setAddress(address);
		user.setGender(gender);
		user.setSal(sal);
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
	}
	finally
	{
		DBUtil.closeResQuery(rs);
	}
	
%>
<form action="/ces/tab/update.jsp" method="post">
<input type="hidden" value="<%=user.getUserId() %>" name="userId">
<table class="tableb" align="center">
	
	<tr>
		<td style="text-align: center;background-color: #E7F2FA;">用户名:</td>
		<td><input type="text" name="username" value="<%=user.getUsername() %>"></td>
	</tr>
	<tr>
		<td style="text-align: center;background-color: #E7F2FA;">密码:</td>
		<td><input type="password" name="password" value="<%=user.getPassword() %>"></td>
	</tr>
	<tr>
		<td style="text-align: center;background-color: #E7F2FA;">性别:</td>
		<td>
			<input type="radio" name="gender" value="1" 
			<%
				if(user.getGender() == 1)
				{
			%>
				checked
			<%
				}
			%>
			>男&nbsp;
			<input type="radio" name="gender" value="0"
			<%
				if(user.getGender() == 0)
				{
			%>
				checked
			<%
				}
			%>
			>女
		
		</td>
	</tr>
	<tr>
		<td style="text-align: center;background-color: #E7F2FA;">生日:</td>
		<td><input type="text" name="birthday" value="<%=user.getBirthday() %>"></td>
	</tr>
	<tr>
		<td style="text-align: center;background-color: #E7F2FA;">地址:</td>
		<td><input type="text" name="address" value="<%=user.getAddress() %>"></td>
	</tr>
	<tr>
		<td style="text-align: center;background-color: #E7F2FA;">薪资:</td>
		<td><input type="text" name="sal" value="<%=user.getSal()%>"></td>
	</tr>
	<tr >
		<td colspan="2" align="right">
			<input type="submit" value="修改">
		</td>
	</tr>
</table>
</form>
</body>
</html>

如有错误,欢迎指正!