jsp中怎么改才能将输入模式改为获取当前时间的点击按钮然后存到数据库中?
publicStringkaoqinadd(){HttpServletRequestrequest=this.getRequest();request.setAttrib...
public String kaoqinadd() {
HttpServletRequest request = this.getRequest();
request.setAttribute("userlist", userDao.selectBeanList(0, 9999, " where deletestatus=0 and role=2"));
request.setAttribute("url", "method!kaoqinadd2");
request.setAttribute("biaoti", "员工考勤添加");
this.setUrl("kaoqin/kaoqinadd.jsp");
return SUCCESS;
}
//添加员工考勤操作
public void kaoqinadd2() throws IOException {
HttpServletRequest request = this.getRequest();
PrintWriter writer = this.getPrintWriter();
String userid = request.getParameter("userid");
String shangban = request.getParameter("shangban");
String xiaban = request.getParameter("xiaban");
Kaoqin bean = new Kaoqin();
bean.setShangban(shangban);
bean.setUser(userDao.selectBean(" where id= "+userid));
bean.setXiaban(xiaban);
kaoqinDao.insertBean(bean);
writer.print("<script language=javascript>alert('操作成功');window.location.href='method!kaoqinlist';</script>");
}
原来时间是需要输入的,我想把那个输入框直接变成按钮,点击就可以保存当前时间 展开
HttpServletRequest request = this.getRequest();
request.setAttribute("userlist", userDao.selectBeanList(0, 9999, " where deletestatus=0 and role=2"));
request.setAttribute("url", "method!kaoqinadd2");
request.setAttribute("biaoti", "员工考勤添加");
this.setUrl("kaoqin/kaoqinadd.jsp");
return SUCCESS;
}
//添加员工考勤操作
public void kaoqinadd2() throws IOException {
HttpServletRequest request = this.getRequest();
PrintWriter writer = this.getPrintWriter();
String userid = request.getParameter("userid");
String shangban = request.getParameter("shangban");
String xiaban = request.getParameter("xiaban");
Kaoqin bean = new Kaoqin();
bean.setShangban(shangban);
bean.setUser(userDao.selectBean(" where id= "+userid));
bean.setXiaban(xiaban);
kaoqinDao.insertBean(bean);
writer.print("<script language=javascript>alert('操作成功');window.location.href='method!kaoqinlist';</script>");
}
原来时间是需要输入的,我想把那个输入框直接变成按钮,点击就可以保存当前时间 展开
2个回答
2016-06-13
展开全部
这是我昨天写的一种实现方法,请参考下
public class AddWZ extends HttpServlet
{
Connection conn = null; // 数据库的连接
Statement stmt = null; // 语句
ResultSet rs = null; // 结果
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException{
res.setContentType("text/html;charset=gb2312");
String bt = req.getParameter("bt");
String nr = req.getParameter("nr");
PrintWriter out = res.getWriter();
try{
// 用户信息添加到数据库
// 准备创建一个数据库的连接
Class.forName("com.mysql.jdbc.Driver"); // 拿到数据库驱动的对象
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/boke?user=root&password=root&Unicode=true&characterEncoding=gbk"); // 连接数据库
stmt = conn.createStatement(); // 创建一个可以传递SQL语句的对象
stmt.executeUpdate("SET NAMES gb2312");
//获取系统时间
Date rq = new Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
String cjtime = df.format(rq);
//String insert = "INSERT INTO wztbl VALUES(DEFAULT, '标题', '内容', 创建的时间, 修改的时间, DEFAULT)"
把时间和内容都写到数据库里
int jieguo = stmt.executeUpdate("INSERT INTO wztbl VALUES('"+bt+"','"+nr+"','"+cjtime+"')");
out.println("<br>插入信息成功!");
conn.close();
}catch(Exception e){
// 如果捕捉到异常,则...
System.out.println(e);
}
}
}
public class AddWZ extends HttpServlet
{
Connection conn = null; // 数据库的连接
Statement stmt = null; // 语句
ResultSet rs = null; // 结果
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException{
res.setContentType("text/html;charset=gb2312");
String bt = req.getParameter("bt");
String nr = req.getParameter("nr");
PrintWriter out = res.getWriter();
try{
// 用户信息添加到数据库
// 准备创建一个数据库的连接
Class.forName("com.mysql.jdbc.Driver"); // 拿到数据库驱动的对象
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/boke?user=root&password=root&Unicode=true&characterEncoding=gbk"); // 连接数据库
stmt = conn.createStatement(); // 创建一个可以传递SQL语句的对象
stmt.executeUpdate("SET NAMES gb2312");
//获取系统时间
Date rq = new Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
String cjtime = df.format(rq);
//String insert = "INSERT INTO wztbl VALUES(DEFAULT, '标题', '内容', 创建的时间, 修改的时间, DEFAULT)"
把时间和内容都写到数据库里
int jieguo = stmt.executeUpdate("INSERT INTO wztbl VALUES('"+bt+"','"+nr+"','"+cjtime+"')");
out.println("<br>插入信息成功!");
conn.close();
}catch(Exception e){
// 如果捕捉到异常,则...
System.out.println(e);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询