该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
HTML代码:
联系人姓名
联系人手机号
联系人邮箱
确定
JS代码:
function InsertLXR(){
varlinkmanName =$("#linkmanName").val();
varlinkmanPhone =$("#linkmanPhone").val();
varlinkmanEmail =$("#linkmanEmail").val();
if(linkmanName!=""){
$.post("${ctx}/servlet/PNRServlet?type=linkman", {linkmanName: linkmanName, linkmanPhone: linkmanPhone, linkmanEmail:linkmanEmail}, function (data) {
if (data=!"") {
layer.alert(data,{content:"新增联系人成功!",icon: 0, title: '提示' });
} else{
layer.alert(data,{content:"新增联系人失败!",icon: 0, title: '提示' });
};
});
}
};
Servlet代码:
publicvoid linkman(HttpServletRequestrequest, HttpServletResponse response)
throws ServletException, IOException {// 新增联系人
response.setContentType("text/html;charset=utf-8");
StringlinkmanName = request.getParameter("linkmanName");// 获取jsp页面的linkmanName
String linkmanPhone= request.getParameter("linkmanPhone");
StringlinkmanEmail = request.getParameter("linkmanEmail");
LinkmanPo u= new LinkmanPo();
u.setLinkmanName(linkmanName);
u.setLinkmanPhone(linkmanPhone);
u.setLinkmanEmail(linkmanEmail);
boolean a = ip.InsertLinkman(u);
}
Dao实现类代码:
publicboolean InsertLinkman(LinkmanPo u) {
Stringsql = "insert intolinkman(linkmanName,linkmanPhone,linkmanEmail) values(?,?,?);";
boolean a=false;
try {
con = DBUtil.getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, u.getLinkmanName());
ps.setString(2, u.getLinkmanPhone());
ps.setString(3, u.getLinkmanEmail());
//ps.executeUpdate();//重复写会执行两次
if (ps.executeUpdate() > 0) {//返回的是它受影响的行数
a = true;
}
System.out.println(u.getLinkmanName() + "新增成功!");
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(con, ps, rs);
}
return a;
}