我正在为我的大学做评估,我的老师给了我一些初始代码以供复制,现在我陷入了自己的代码中。基本上,此代码创建一个新对象,以ID插入数据库。我需要捕获在对象中创建的交易ID,才能将其发送到下一页。查看交易(市场门户)。对不起我的英语,但是有点难。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
int user_id = Integer.parseInt(request.getParameter("user_id"));
int feed_id = Integer.parseInt(request.getParameter("feed_id"));
Date now = new java.sql.Date(System.currentTimeMillis());
//int transaction_done =0; MEANS NO TRANSACTION
//int transaction_done =1; MEANS USER NTERESTED SEND APPLICATION TO REACH FEEDER
//int transaction_done =2; MEANS FEEDER DECLINE TRANSACTION
//int transaction_done =3; MEANS TRANSACTION SUCCESSFULL, PROCEED WITH REVIEW
int transaction_done =1;
TransactionService objTransactionService = new TransactionService();
Transaction objTransaction = new Transaction(0, feed_id,user_id,now,transaction_done);
if (objTransactionService.saveTransaction(objTransaction)) {
HttpSession sesion=request.getSession();
String done = "transaction in process! well done.";
sesion.setAttribute("done", done);
response.sendRedirect("chat.jsp?done=true");
} else {
HttpSession sesion=request.getSession();
String done = "Error, try again.";
sesion.setAttribute("done", done);
response.sendRedirect("chat.jsp?done=false");
}
}
希望你能帮助我。