Java Http会话计算
我正在制作一个购物web应用程序,我有第一个html表单,如下所示:Java Http会话计算,java,servlets,Java,Servlets,我正在制作一个购物web应用程序,我有第一个html表单,如下所示: <!DOCTYPE html> <html> <head> <META HTTP-EQUIV="Pragma" CONTENT="no cache"> <META HTTP-EQUIV="Cache-control" CONTENT="no cache"> <META HTTP-EQUIV="Expires" CONT
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no cache">
<META HTTP-EQUIV="Cache-control"
CONTENT="no cache">
<META HTTP-EQUIV="Expires" CONTENT="0">
<TITLE>Shopping Cart</TITLE>
<title> Shopping Cart </title>
</head>
<body>
<center>
<h3> Simple Shopping Cart </h3>
<form method=post action="Selection">
<table>
<tr>
<td>
<input type="radio" name="Product" value="Apples" checked>
<font color=blue> Apples </font>
</td>
</tr>
<tr>
<td>
<input type="radio" name="Product" value="Pears">
<font color=blue> Pears </font>
</td>
</tr>
<tr>
<td>
<input type="radio" name="Product" value="Checkout">
<font color=blue> Go To the checkout </p> </font>
</td>
</tr>
</table>
<BR><BR><BR>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
最后,这是Checkout Servlet:
我的问题是计算成本和总成本变量
结果,每个购物结帐都被指定为零
我的代码出了什么问题?产品将其命名为所选产品的枚举,您希望将Apple与当前产品进行比较 替换
if (prodNames.equals("Apples")) { // never true
cost = APPLES_PRICE * wt;
} else if (prodNames.equals("Pears")) { // never true
cost = PEARS_PRICE * wt;
}
与:
if (product.equals("Apples")) {
cost = APPLES_PRICE * wt;
} else if (product.equals("Pears")) {
cost = PEARS_PRICE * wt;
}
顺便说一下,您应该了解如何调试应用程序。它将帮助您管理此类问题
if (prodNames.equals("Apples")) { // never true
cost = APPLES_PRICE * wt;
} else if (prodNames.equals("Pears")) { // never true
cost = PEARS_PRICE * wt;
}
if (product.equals("Apples")) {
cost = APPLES_PRICE * wt;
} else if (product.equals("Pears")) {
cost = PEARS_PRICE * wt;
}