gpt4 book ai didi

java - 如何在不访问数据库的情况下获取值?

转载 作者:行者123 更新时间:2023-12-02 05:09:13 26 4
gpt4 key购买 nike

我需要你的帮助。我目前正在做一个采购项目。用户单击“添加到购物车”后,该商品将被添加到购物车,但尚未保存到数据库中。然后,我会让用户点击结帐。 PurchaseCart.jsp 将执行操作并将它们带到PurchaseCheckOut servlet。那么,如何获取之前的数据呢?

PurchaseCart.jsp

<body>
<%!List<Double> stockArray = new ArrayList<Double>() ;%>

<%!List<Object> list1 = new ArrayList<Object>();%>

<% Object o = request.getAttribute("purchased");
list1.add(o);
int size = list1.size();
double stockPrice = (Double)request.getAttribute("stockPriceReal");
if(stockArray.size() == 0)
{
stockArray.add(stockArray.size(),stockPrice);
}
else {

stockArray.add(stockArray.size(), stockPrice); } %>
<form action = "../PurchaseCheckOut">
<table border="1">
<thead>
<tr>
<th>No.</th>
<th>Purchase Details ID</th>
<th>Stock ID</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>

<% for (int g = 0; g < size; g ++) { %>
<tr>
<% String toString = list1.get(g).toString();
String subString1 = toString.substring(0,7);
String subString2 = toString.substring(7,9);
String subString3 = toString.substring(9,14);
%>
<td><%= g +1 %></td>
<td><%= subString1 %></td>
<td><%= subString2 %></td>
<td><%= subString3 %></td>
<td><%= stockArray.get(g).toString() %></td>


</tr>

<% } %>
</tbody>
</table>
<input type = submit name="checkout" value="Check Out">
</form>
</body>

PurchaseCheckOut.java(我已经完成了持久部分和重定向部分,但我不知道如何获取该值。?是我传入的值。)

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {

PurchaseService ps = new PurchaseService(em);
utx.begin();
boolean success = ps.addPurchaedetails(?);
utx.commit();
HttpSession session = request.getSession();
session.setAttribute("success", success);
response.sendRedirect("MemberAccess/AddConfirm.jsp");
}
catch (Exception ex) {
Logger.getLogger(PurchaseCheckOut.class.getName()).log(Level.SEVERE, null, ex);
}

添加购买详情的购买服务

 public boolean addPurchasedetails(Purchasedetails purcD) {
mgr.persist(purcD);
return true; }

购买的结构如下:PurchaseM.jsp(让用户选择)->PurchaseCreate.java(将所有值传递到购物车)->PurchaseCart.jsp(显示值(尚未持久化))-> PurchaseCheckOut.java(persist) -> AddConfirm.jsp(显示“您已完成”)

最佳答案

您可以将添加到购物车的值存储在 session 对象中,并在您需要的任何地方进行引用。

关于java - 如何在不访问数据库的情况下获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27473673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com