JSP+servlet+JavaBean

第一步:openfund工程下建立包edu.fzu.openfund.utils。在edu.fzu.openfund.utils包下新建类DBUtils,实现getConnreleaseResource方法。

public class DBUtils {
    private static final String CONN_URL = "jdbc:mysql://localhost:3306/openfunddb";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "123456";
    public static Connection getConn()
    {
        Connection conn = null;
        try
        {
        	Class.forName("com.mysql.jdbc.Driver");
        	conn= DriverManager.getConnection(CONN_URL,USERNAME,PASSWORD);
        	
        } catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        } catch (SQLException e)
        {
            e.printStackTrace();
        }
        return conn;
    }
    public static void releaseResource(Connection conn, PreparedStatement pstmt,ResultSet rset)
    {
        try
        {
        	if(conn!=null)
        		conn.close();
        	if(pstmt!=null)
        		pstmt.close();
        	if(rset!=null)
        		rset.close();
        } catch (SQLException e)
        {
            e.printStackTrace();
        }
    }
}
第二步: openfund工程下建立包edu.fzu.openfund.dao。在edu.fzu.openfund.dao下新建接口ClientDao、新建类ClientDaoJDBCImpl实现ClientDao接口。
public class ClientDaoJDBCImpl implements ClientDao {
	private static  String insertSql = "insert into client value(?,?,?,?,?,?,?,?)";
	public int createClient(Client client) {
		try {
			Connection conn=DBUtils.getConn();
			PreparedStatement  pstmt=conn.prepareStatement(insertSql);
			pstmt.setString(1, client.getIDCardNO());
			pstmt.setString(2, client.getClientName());
			pstmt.setString(3, client.getClientSex());
			pstmt.setString(4, client.getClientPhone());
			pstmt.setString(5, client.getClientAddress());
			pstmt.setString(6, client.getClientEmail());
			pstmt.setString(7, client.getClientHobby());
			Date date =new Date(client.getClientCreateDate().getTime());
			pstmt.setDate(8, date);
			pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		return 0;
	}
第三步:openfund工程下建立包edu.fzu.openfund.service。新建接口ClientService新建类ClientServiceImpl实现ClientService接口。

public class ClientServiceImpl implements ClientService {
	public int createClient(Client client) {
		ClientDao clientDao = new ClientDaoJDBCImpl();
		List list=clientDao.getClientByID(client.getIDCardNO());
		if(list!=null)
			return 0;
		else
		return clientDao.createClient(client);
	}
第四步:修改 ClientMgrServlet类的代码。

else if (mid == 2) {
                       ClientService clientService=new ClientServiceImpl();
                       List all =clientService.getAllClient();
                       request.setAttribute("list",all);
                       request.getRequestDispatcher("/Client/showClients.jsp?rid=0").forward(request, response);
                    }
第五步: 编写 showClients.jsp。

<body>
	<center>
		<font   size=7>客户详情列表</font>
		<table border="1">
			<tr>
				<td>身份证号</td>
				<td>姓名</td>
				<td>性别</td>
				<td>手机号码</td>
				<td>地址</td>
				<td>电子邮箱</td>
				<td>爱好</td>
				<td>创建日期</td>
				<td>操作</td>
			</tr>
			<%
				List all = (ArrayList) request.getAttribute("list");
				Client client = null;
				Iterator it = all.iterator();
				while (it.hasNext()) {
					 client = (Client) it.next();
			%>
			<tr>
				<td><%=client.getIDCardNO()%></td>
				<td><%=client.getClientName()%></td>
				<td><%=client.getClientSex()%></td>
				<td><%=client.getClientPhone()%></td>
				<td><%=client.getClientAddress()%></td>
				<td><%=client.getClientEmail()%></td>
				<td><%=client.getClientHobby()%></td>
				<td><%=client.getClientCreateDate()%></td>
				<td>
					<form name="f">
						<input type="button" name="Delete" value="删除" οnclick=Del>
						<input type="button" name="Edit" value="修改" οnclick=Edit>
					</form>
				</td>
			</tr>
		 <%
          }
          %>
		</table>
</body>

第六步:编写left.jsp。

<span class="STYLE3"><a href="clientMgr?mid=0" target="contentFrame">新客户开户</span>
<span class="STYLE3"><a href="clientMgr?mid=2" target="contentFrame">客户信息列表</span>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值