public class AddServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req
, HttpServletResponse resp
)
throws ServletException
, IOException
{
req
.setCharacterEncoding("utf-8");
resp
.setContentType("text/html;charset=utf-8");
String name
= req
.getParameter("name");
double price
= Double
.parseDouble(req
.getParameter("price"));
String desc
= req
.getParameter("desc");
goods g
= new goods(name
, price
, desc
);
goodsDao gd
= new goodsDao();
int state
= gd
.addServlet(g
);
PrintWriter pw
= resp
.getWriter();
if(state
!=0){
pw
.print("<script>");
pw
.print("alert('添加成功');");
pw
.print("location.href='QueryServlet'");
pw
.print("</script>");
}else{
pw
.print("<script>");
pw
.print("alert('添加失败!');");
pw
.print("location.href='add.jsp'");
pw
.print("</script>");
}
}
}
转载请注明原文地址:https://tech.qufami.com/read-18737.html