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();
}
}
}
最近下载更多
最近浏览更多
feifeifei123123123
7月15日
暂无贡献等级
酷少小新 LV2
6月8日
新哥新奇士橙 LV5
1月26日
yongle LV1
2024年12月31日
微信网友_7313889549307904
2024年12月27日
暂无贡献等级
1453666970
2024年12月27日
暂无贡献等级
ma406805131 LV19
2024年12月19日
xiaoaitx LV8
2024年11月18日
张泽帅 LV6
2024年10月18日
赵鑫cdsaljkdfsa LV11
2024年7月2日

