📄 applygoods.java
字号:
package xiaoshou.servlets;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import xiaoshou.classes.CClient;
import xiaoshou.classes.CGood;
import xiaoshou.classes.CUser;
import xiaoshou.javabeans.Operator;
public class ApplyGoods extends HttpServlet {
/**
* Constructor of the object.
*/
public ApplyGoods() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* 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 {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* 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 {
request.setCharacterEncoding("gb2312");
String clientname=request.getParameter("client");
String addr=request.getParameter("addr");
String date=request.getParameter("date");
CUser user=(CUser)request.getSession().getAttribute("user");
/*检查所填客户是否存在 */
CClient client=Operator.queryClientByName(clientname);
if(client==null){
request.setAttribute("msg", "客户姓名不存在!");
request.getRequestDispatcher("/xiaoshou/applyGoods.jsp").forward(request, response);
return;
}
/* **************************************************/
/*添加订单*******************************************/
boolean r=false;
r=Operator.newOrder(client.getId(),clientname,user.getSellid(),
user.getSell(),date,user.getId(),user.getName(),
"未审核","普通","",addr);
if(!r){
request.setAttribute("result", "订货失败!");
request.getRequestDispatcher("/xiaoshou/result.jsp").forward(request, response);
return;
}
/* ********************************************** */
/*添加订单明细************************************************/
//先求出订单号orderid
int orderid=Operator.queryOrderID(clientname, date);
if(orderid<0){
request.setAttribute("result", "订货失败!");
request.getRequestDispatcher("/xiaoshou/result.jsp").forward(request, response);
return;
}
//逐项添加购物车里的内容到订货明细
ArrayList list=(ArrayList)request.getSession().getAttribute("lists");
for(int i=0;i<list.size();i++){
CGood good=(CGood)list.get(i);
r=Operator.newOrderDetail(orderid, good.getId(), good.getNum(), good.getName());
if(!r){
request.setAttribute("result", "订货失败!");
request.getRequestDispatcher("/xiaoshou/result.jsp").forward(request, response);
return;
}
}
/* *****************************************************/
if(r)
request.setAttribute("result", "订货成功!");
else
request.setAttribute("result", "订货失败!");
//清空购物车
request.getSession().removeAttribute("lists");
request.getRequestDispatcher("/xiaoshou/result.jsp").forward(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -