package com.java.servlet;

import java.io.IOException;
import java.sql.Connection;

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

import com.java.dao.InfoDao;
import com.java.model.Info;
import com.java.util.DbUtil;
import com.java.util.StringUtil;

public class AddInfo extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		String name = req.getParameter("name");
		String sex = req.getParameter("sex");
		String age = req.getParameter("age");
		String join_time = req.getParameter("join_time");
		String card = req.getParameter("card");
		
		if (StringUtil.isEmpty(name)||
				StringUtil.isEmpty(sex)||
				StringUtil.isEmpty(age)||
				StringUtil.isEmpty(join_time)||
				StringUtil.isEmpty(card)
				) {
			req.setAttribute("error", "不能留空");
			req.getRequestDispatcher("addInfo.jsp").forward(req, resp);
			return;
		}
		
		Info info = new Info(name,sex,
				Integer.parseInt(age),
				Integer.parseInt(join_time),
				Integer.parseInt(card));
		
		DbUtil db = new DbUtil();
		InfoDao infoDao = new InfoDao();
		try {
			Connection con = db.getCon();
			infoDao.infoAdd(con,info);
			
			req.setAttribute("error", "添加成功");
			req.getRequestDispatcher("addInfo.jsp").forward(req, resp);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}

}
最近下载更多
asddwh  LV12 2023年12月26日
李林112233  LV2 2023年12月4日
321170193  LV6 2023年11月11日
jiemomo  LV12 2023年10月18日
麻辣香锅加锐澳  LV6 2023年8月19日
小顾顾顾顾顾  LV4 2023年6月7日
hmdzmsl12  LV2 2023年6月1日
qq2901732871  LV9 2023年5月20日
187236  LV4 2023年3月23日
湘牛牛刘  LV2 2023年2月8日
最近浏览更多
一起加油  LV3 2小时前
FORGOT  LV1 3月31日
Lilei66 3月27日
暂无贡献等级
hxy19991216  LV4 2023年12月29日
无敌最俊朗啊  LV2 2023年12月29日
hanzhuohong  LV1 2023年12月27日
asddwh  LV12 2023年12月25日
zeng1206  LV5 2023年12月25日
微信网友_6791526949031936 2023年12月24日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友