JavaWeb:增 删 改 查

文件信息

 

注册

package com.sunguoguo.web.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sunguoguo.entity.Customer;
import com.sunguoguo.service.CustomerServicelmp;

public class CustomerServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("get请求上");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		//设置响应的字符集编码
		resp.setContentType("text/html;charset=UTF-8");
		PrintWriter writer = resp.getWriter();
		 System.out.println("post请求");
		String accont = req.getParameter("accont");
		String password = req.getParameter("password");
		String name = req.getParameter("name");
		//将数据放入实体类中
				Customer customer = new Customer( name, password, new Date(), accont);
				CustomerServicelmp cs = new CustomerServicelmp();
				cs.addCustomer(customer);
        //查询信息
		CustomerServicelmp csi = new CustomerServicelmp();
		List<Customer> list=csi.QueryServiceImp();
	
		
		boolean b = cs.addCustomer(customer);
		if(b){
			//将查询到的数据传入容器
			req.setAttribute("l", list);
			req.getRequestDispatcher("Querry.jsp").forward(req, resp);
			writer.write("注册成功");
		}else{
			writer.write("注册失败");
		}
       
	}

}

 删除

package com.sunguoguo.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sunguoguo.service.CustomerServicelmp;

public class DeleteServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		//设置响应的字符集编码
		resp.setContentType("text/html;charset=UTF-8");
          CustomerServicelmp csi = new CustomerServicelmp();
          String cid = req.getParameter("id");
          PrintWriter writer = resp.getWriter();
          
          boolean b=csi.Delete(cid);
          if(b){
        	  req.getRequestDispatcher("reg.jsp").forward(req, resp);
          }else{
        	  writer.write("删除失败<a href='Querry.jsp'>点击返回查询</a>");
          }
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

}

注册

查询

查询页面代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import= "java.util.*"%>
    <%@ page import= "java.lang.*"%>
    <%@ page import= "com.sunguoguo.entity.Customer"%>
<!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>
</head>
<body>
      <%! 
      int id;
      String username;
      String password;
      Date time;
      String accont;
      List<Customer> li;
      String ss;
      %>
      <%
      li=(List)request.getAttribute("l");
      ss=(String)request.getAttribute("chenggong");
    
      %>
      <table align='center' width='80%' border='1px' cellspacing='0px' cellpadding='0px'>
           <tr>
           <th>客户编号</th><th>姓名</th><th>密码</th><th>账号</th><th>注册时间</th><th>操作</th>
           </tr>
           <%      for(int i=0;i<li.size();i++){Customer c= li.get(i); int id=c.getId(); String username=c.getUsername();String password=c.getPassword();Date time=c.getTime();String accont=c.getAccont();%>
           <tr>
           <td><%=id %></td>
           <td><%=username%></td>
           <td><%=password %></td>
           <td><%=accont %></td>
           <td><%=time %></td>
           <td><a href='del?id=<%=id %>'>删除</a><a href='Updata.html?id=<%=id %>'>修改</a></td>
           </tr>
           <% }%>
      </table>
      <div>
          <h1><=ss></h1>
      </div>
</body>
</html>

 删除(点点)

 

 谢谢观看~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值