JavaWeb:增 删 改 查

文件信息

JavaWeb:增 删 改 查_第1张图片

 

注册

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 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("删除失败点击返回查询");
          }
	}

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

}

注册

JavaWeb:增 删 改 查_第2张图片

查询

查询页面代码

<%@ 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"%>




Insert title here


      <%! 
      int id;
      String username;
      String password;
      Date time;
      String accont;
      List li;
      String ss;
      %>
      <%
      li=(List)request.getAttribute("l");
      ss=(String)request.getAttribute("chenggong");
    
      %>
      
           <%      for(int i=0;i
           
           <% }%>
      
客户编号姓名密码账号注册时间操作
<%=id %> <%=username%> <%=password %> <%=accont %> <%=time %> 删除修改

<=ss>

 删除(点点)

 

 谢谢观看~

你可能感兴趣的:(servlet,java,开发语言)