package com.action;

import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

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

import com.dao.DB;
import com.orm.Ttea;

public class tea_servlet extends HttpServlet
{
	@Override
	public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException 
	{
        String type=req.getParameter("type");
		
		if(type.endsWith("teaAdd"))
		{
			teaAdd(req, res);
		}
		if(type.endsWith("teaDel"))
		{
			teaDel(req, res);
		}
		if(type.endsWith("teaMana"))
		{
			teaMana(req, res);
		}
		
		if(type.endsWith("teaAll"))
		{
			teaAll(req, res);
		}
	}
	
	
	public void teaAdd(HttpServletRequest req,HttpServletResponse res)
	{
		String bianhao=req.getParameter("bianhao");
		String name=req.getParameter("name");
		String sex=req.getParameter("sex");
		String age=req.getParameter("age");
		
		String loginname=req.getParameter("loginname");
		String loginpw=req.getParameter("loginpw");
		String del="no";
		String id=null;
		
		
		String sql="insert into t_tea(bianhao,name,sex,age,loginname,loginpw,del) values(?,?,?,?,?,?,?)";
		Object[] params={bianhao,name,sex,age,loginname,loginpw,del};
		DB mydb=new DB();
		mydb.doPstm(sql, params);
		mydb.closed();
		
		req.setAttribute("message", "²Ù×÷³É¹¦");
		req.setAttribute("path", "tea?type=teaMana");
		
        String targetURL = "/common/success.jsp";
		dispatch(targetURL, req, res);
	}
	
	public void teaDel(HttpServletRequest req,HttpServletResponse res)
	{
		String sql="update t_tea set del='yes' where id="+Integer.parseInt(req.getParameter("id"));
		Object[] params={};
		DB mydb=new DB();
		mydb.doPstm(sql, params);
		mydb.closed();
		
		req.setAttribute("message", "²Ù×÷³É¹¦");
		req.setAttribute("path", "tea?type=teaMana");
		
        String targetURL = "/common/success.jsp";
		dispatch(targetURL, req, res);
	}

	public void teaMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
	{
		List teaList=new ArrayList();
		String sql="select * from t_tea where del='no'";
		Object[] params={};
		DB mydb=new DB();
		try
		{
			mydb.doPstm(sql, params);
			ResultSet rs=mydb.getRs();
			while(rs.next())
			{
				Ttea tea=new Ttea();
				
				tea.setId(rs.getInt("id"));
				tea.setBianhao(rs.getString("bianhao"));
				tea.setName(rs.getString("name"));
				tea.setSex(rs.getString("sex"));
				
				tea.setAge(rs.getString("age"));
				tea.setLoginname(rs.getString("loginname"));
				tea.setLoginpw(rs.getString("loginpw"));
				tea.setDel(rs.getString("del"));
				
				teaList.add(tea);
		    }
			rs.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		mydb.closed();
		
		req.setAttribute("teaList", teaList);
		req.getRequestDispatcher("admin/tea/teaMana.jsp").forward(req, res);
	}
	
	public void teaAll(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
	{
		List teaList=new ArrayList();
		String sql="select * from t_tea where del='no'";
		Object[] params={};
		DB mydb=new DB();
		try
		{
			mydb.doPstm(sql, params);
			ResultSet rs=mydb.getRs();
			while(rs.next())
			{
                Ttea tea=new Ttea();
				
				tea.setId(rs.getInt("id"));
				tea.setBianhao(rs.getString("bianhao"));
				tea.setName(rs.getString("name"));
				tea.setSex(rs.getString("sex"));
				
				tea.setAge(rs.getString("age"));
				tea.setLoginname(rs.getString("loginname"));
				tea.setLoginpw(rs.getString("loginpw"));
				tea.setDel(rs.getString("del"));
				
				teaList.add(tea);
		    }
			rs.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		mydb.closed();
		
		req.setAttribute("teaList", teaList);
		req.getRequestDispatcher("qiantai/tea/teaAll.jsp").forward(req, res);
	}
	
	
	public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) 
	{
		RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
		try 
		{
		    dispatch.forward(request, response);
		    return;
		} 
		catch (ServletException e) 
		{
                    e.printStackTrace();
		} 
		catch (IOException e) 
		{
			
		    e.printStackTrace();
		}
	}
	@Override
	public void init(ServletConfig config) throws ServletException 
	{
		super.init(config);
	}
	
	@Override
	public void destroy() 
	{
		
	}
}
最近下载更多
你爹正在加载中  LV4 2023年7月19日
ZDM133  LV2 2023年5月22日
wangdongtai  LV31 2022年5月20日
ll23344y  LV2 2022年2月15日
夜星1111  LV1 2022年1月6日
hshhshh  LV1 2021年12月26日
Start1  LV15 2021年11月25日
ssssha  LV1 2021年7月6日
ericxu1116  LV24 2021年6月28日
Rovann  LV1 2021年6月20日
最近浏览更多
zayuchuan 1月3日
暂无贡献等级
asddwh  LV12 2023年12月26日
hanzhuohong  LV1 2023年12月25日
komorebi123987  LV5 2023年12月9日
小芳同学  LV1 2023年12月5日
去码头整点薯条  LV3 2023年11月15日
wbx666  LV1 2023年9月25日
你爹正在加载中  LV4 2023年7月19日
29693748  LV1 2023年7月6日
yewang666  LV1 2023年6月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友