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(); } } }
最近下载更多
最近浏览更多
一起加油 LV3
2小时前
FORGOT LV1
3月31日
Lilei66
3月27日
暂无贡献等级
微信网友_6829521472425984 LV5
1月20日
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日
暂无贡献等级