package myBean; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.sql.*; import java.util.*; public class ChangeAmountServlet extends HttpServlet { /** * Constructor of the object. */ public ChangeAmountServlet() { super(); } public void destroy() { super.destroy(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=GB2312"); PrintWriter out = response.getWriter(); String t_goodsId; String t_goodsAmount; t_goodsId=request.getParameter("goodId"); t_goodsAmount=request.getParameter("name1"); ShoppingCart a=new ShoppingCart(); ConnectManager b=new ConnectManager(); Statement stmt1; try { stmt1 = b.conn.createStatement(); String sqlString = "select * from good1 where goodsId='"+t_goodsId+"'"; ResultSet rs=stmt1.executeQuery(sqlString); a.changeAmount(t_goodsId, t_goodsAmount); response.sendRedirect("ShopCart.jsp"); } catch (SQLException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }