资源简介
用了ajax做购物车,购物车数据存入数据库 基本功能实现
代码片段和文件信息
package action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.Service;
import service.impl.Iservice;
public class BuyAction extends HttpServlet {
/**
* Constructor of the object.
*/
public BuyAction() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts “destroy“ string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
this.doPost(request response);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
String username = (String) request.getSession().getAttribute(“username“);
String totalPrice = request.getParameter(“totalPrice“);
Service s = new Iservice();
s.setOrderId(username);
int oid = s.getOrderId();
System.out.println(username);
System.out.println(oid);
ArrayList list = s.searchBook(username);
for(object num:list){
int count=s.getCount(Integer.parseInt(num.toString())username);
String price = s.getPrice(Integer.parseInt(num.toString()));
s.insertBooks(oidInteger.parseInt(num.toString()) count pricetotalPrice);
System.out.println(count);
System.out.println(price);
}
s.delCar(username);
request.getRequestDispatcher(“shopping-success.jsp“).forward(request response);
}
/**
* Initialization of the servlet.
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-12-31 11:53 bookshop\
文件 1093 2013-12-31 11:53 bookshop\.classpath
文件 1333 2013-12-31 11:53 bookshop\.project
目录 0 2013-12-31 11:53 bookshop\.settings\
文件 522 2013-12-31 11:53 bookshop\.settings\.jsdtscope
文件 364 2013-12-31 11:53 bookshop\.settings\org.eclipse.jdt.core.prefs
文件 483 2013-12-31 11:53 bookshop\.settings\org.eclipse.wst.common.component
文件 414 2013-12-31 11:53 bookshop\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2013-12-31 11:53 bookshop\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2013-12-31 11:53 bookshop\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2013-12-31 11:53 bookshop\src\
目录 0 2013-12-31 11:53 bookshop\src\action\
文件 2613 2013-12-31 11:53 bookshop\src\action\BuyAction.java
文件 2699 2013-12-31 11:53 bookshop\src\action\CarAction.java
文件 2159 2013-12-31 11:53 bookshop\src\action\ChageNumAction.java
文件 2149 2013-12-31 11:53 bookshop\src\action\CheckRegister.java
文件 957 2013-12-31 11:53 bookshop\src\action\CodeFilter.java
文件 2027 2013-12-31 11:53 bookshop\src\action\DelAction.java
文件 2430 2013-12-31 11:53 bookshop\src\action\GoCarAction.java
文件 2961 2013-12-31 11:53 bookshop\src\action\IndexAction.java
文件 2783 2013-12-31 11:53 bookshop\src\action\LoginAction.java
文件 1591 2013-12-31 11:53 bookshop\src\action\LoginFilter.java
文件 1980 2013-12-31 11:53 bookshop\src\action\LoginOut.java
文件 3016 2013-12-31 11:53 bookshop\src\action\OrderAction.java
文件 2784 2013-12-31 11:53 bookshop\src\action\RegisterAction.java
目录 0 2013-12-31 11:53 bookshop\src\dao\
文件 752 2013-12-31 11:53 bookshop\src\dao\BookDao.java
目录 0 2013-12-31 11:53 bookshop\src\dao\bookImpl\
文件 6569 2013-12-31 11:53 bookshop\src\dao\bookImpl\IbookDao.java
文件 514 2013-12-31 11:53 bookshop\src\dao\OrderDao.java
目录 0 2013-12-31 11:53 bookshop\src\dao\orderImpl\
............此处省略94个文件信息
评论
共有 条评论