网站图片模板,昆明网站建设方案报价,wordpress多主题,贵港市建设局网站在实践项目中我们有可能需要做到新增功能#xff0c;新增一张表#xff0c;或是新增多张表。这里我新增的是一张表。 这里主要描述DAO层与Servlet 层#xff1a; DAO 层#xff1a;
public class UserDaoImpl implements UserDao {private Connection con null;private P…在实践项目中我们有可能需要做到新增功能新增一张表或是新增多张表。这里我新增的是一张表。 这里主要描述DAO层与Servlet 层 DAO 层
public class UserDaoImpl implements UserDao {private Connection con null;private PreparedStatement ps null;private ResultSet rs null;private String insertINSERT INTO um_usm_athentication
(Athenticationname,Credit,Apply,Remarks,Identificationname,Vsalidityperiod,ExamineStateID) VALUES(?,?,?,?,?,?,?);
Override
public boolean insert(Userautonym t) {boolean returnA false;try {con DbUtil.getConnection();ps con.prepareStatement(insert);ps.setString(1, t.getAthenticationname());ps.setString(2, t.getCredit());ps.setString(3, t.getApply());ps.setString(4, t.getRemarks());ps.setString(5, t.getIdentificationname());ps.setString(6, t.getVsalidityperiod());ps.setInt(7, t.getExamineStateID());if (ps.executeUpdate() 0) {returnA true;System.out.println(Apply);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{ //关闭流DbUtil.close(con, ps, rs);}return returnA;}
}Servlet层
public void insertprove(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String Athenticationname request.getParameter(Athenticationname);String Credit request.getParameter(Credit);//获取当前系统时间Timestamp datenew Timestamp(System.currentTimeMillis());//定义格式没有显示毫秒DateFormat df new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);//将当前系统时间转换为不显示毫秒情况保存为String类型在dateNow中String dateNow df.format(date);//可以控制台输出dateNow的值System.out.println(系统时间:dateNow);String Apply dateNow;String Remarks request.getParameter(Remarks);String Identificationname request.getParameter(Identificationname);String Vsalidityperiod request.getParameter(Vsalidityperiod);int ExamineStateID Integer.parseInt(request.getParameter(ExamineStateID)); Userautonym userautonym new Userautonym();userautonym.setAthenticationname(Athenticationname);userautonym.setCredit(Credit);userautonym.setApply(Apply);userautonym.setRemarks(Remarks);userautonym.setIdentificationname(Identificationname);userautonym.setVsalidityperiod(Vsalidityperiod);userautonym.setExamineStateID(ExamineStateID);IUserService userService new UserServiceImpl();boolean success userService.insert(userautonym);if (success) {request.getSession().setAttribute(strMsg, 新增成功);} else {request.getSession().setAttribute(strMsg, 新增失败);}response.sendRedirect(LoginServlet?funprovessss);}在页面层用post 提交表单的方法就可以进行传值了。 如
form action${ctx}/servlet/LoginServlet methodpost
input typehidden namefun valueinsertprove/
填写所需字段的name 值
记得在点击新增按钮加上typesubmit
/form