高手啊,快进来吧,实在不行了

YUNYUN_033 2007-05-16 02:47:45
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*" %>
<%@ page session="true" %>
<%@ page import="bookshop.book.*"%>
<%@ page import="bookshop.run.op_book" %>
<%@ page import="bookshop.run.op_buy" %>
<jsp:useBean id="book_list" scope="page" class="bookshop.run.op_book" />
<jsp:useBean id="pay" scope="page" class="bank.bank"/>
<jsp:useBean id="shop" scope="page" class="bookshop.run.op_buy" />

<%
String submits = request.getParameter("payout");
if (submits!=null && !submits.equals(""))

{
int totalint= Integer.parseInt((String)session.getAttribute("total"));
pay.pay("user1",1);

}

String userid = (String) session.getAttribute("userid");
if ( userid == null )
userid = "";
String modi=request.getParameter("modi");
String del = request.getParameter("del");
String payoutCar = request.getParameter("payout");
String clearCar = request.getParameter("clear");
String mesg = "";

if (modi!=null && !modi.equals("")) {
if ( !shop.modiShoper(request) ){
if (shop.getIsEmpty())
mesg = "你要的修改购买的图书数量不足你的购买数量!";
else
mesg = "修改购买数量出错!";
} else {
mesg = "修改成功";
}

}else if ( del != null && !del.equals("") ) {
if ( !shop.delShoper(request) ) {
mesg = "删除清单中的图书时出错!" ;
}
}else if (payoutCar != null && !payoutCar.equals("") ) {
if (shop.payout(request) ) {
mesg = "你的购物车中的物品已提交给本店,你的订单号为 "+ shop.getOrderId() + " 请及时付款,以便我们发货!";
session.removeAttribute("shopcar");
} else {
if(!shop.getIsLogin())
mesg = "你还没有登录,请先<a href=login.jsp>登录</a>后再提交";
else
mesg = "对不起,提交出错,请稍后重试";
}
} else if (clearCar != null && ! clearCar.equals("") ) {
session.removeAttribute("shopcar");
mesg = "购物车中的物品清单已清空";
}


%>

<script language="javascript">

function openScript(url,name, width, height){
var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}
function checklogin() {
if (document.payout.userid.value=="")
{
alert("你还没有登录,请登录后再提交购物清单。");
return false;
}
return true;
}

function check()
{
if (document.change.amount.value<1){
alert("你的购买数量有问题");
document.change.amount.focus();
return false;
}
return true;
}

</script>
<%@include file="inc/head.inc"%>
<br>

<%@include file="inc/sub.inc"%>
<center>
<%
if (!mesg.equals("") )
out.println("<p ><font size=2 color=#ff0000>" + mesg + "</font></p>");

Vector shoplist = (Vector) session.getAttribute("shopcar");
if (shoplist==null || shoplist.size()<0 ){
if (mesg.equals(""))
out.println("<p><font size=2 color=black>你还没有选择购买图书!请先购买</font></p>");
} else {
%>
<table width="778" border="1" cellspacing="2" bgcolor="white" bordercolor="black" align="center">
<tr><a href="booklist.jsp">继续购书</a></font></tr>

<tr width="86%" height="59" class="tableBorder_B"><img src="Images/ico_cart.gif" width="176" height="70"></tr>

<tr align="center" bgcolor="white">
<td><font size=2>图书名称</font></td>
<td><font size=2>作者</font></td>

<td><font size=2>单价(元)</font></td>
<td><font size=2>数量</font></td>
<td colspan =2><font size=2>选择</font></td>
</tr>
<%
float totalprice =0;
int totalamount = 0;
for (int i=0; i<shoplist.size();i++){
allorder iList = (allorder) shoplist.elementAt(i);
if (book_list.getOnebook((int)iList.getBookNo())) {
book bk = (book) book_list.getBooklist().elementAt(0);
totalprice = totalprice + bk.getPrince() * iList.getAmount();
String total=String.valueOf(totalprice);
session.setAttribute("total",total);
totalamount = totalamount + iList.getAmount();
%>
<tr>
<td><font size=2><%= bk.getBookName() %></font></td>
<td align="center"><font size=2><%= bk.getAuthor() %></font></td>

<td align="center"><font size=2><%= bk.getPrince() %></font></td>
<form name="change" method="post" action="shopcar.jsp">
<td align="center">
<input type="text" name="amount" maxlength="4" size="3" value="<%= iList.getAmount() %>" >
</td>
<td align="center" width=55 >

<input type="submit" name="modi" value="修改" onclick="return(check());"></td>
<form name="del" method="post" action="shoperlist.jsp">
<input type="hidden" name="bookid" value="<%= iList.getBookNo() %>" >
<td align=center width=55> <input type="submit" name="del" value="删除">
</td></form>
</tr>
<% }
} %> <tr><td colspan=7 align="right"><br><font size=2>你选择的图书的总金额:<%= totalprice%>元  总数量:<%= totalamount%>本 </font></td></tr>
</table>
<p></p>
<table width="90%" border="0" cellspacing="1" cellpadding="1">
<form name="payout" method="post" action="shopcar.jsp">
<tr><td align="center" valign="bottom">
<input type="hidden" name="userid" value="<%= userid %>">
<input type="hidden" name="totalprice" value="<%= totalprice %>">
</td></tr>
<tr><td align=center>
<input type="submit" name="payout" value="提交" onclick="javascript:return(checklogin());">
</td></tr>
</form>
</table>

<table width="90%" border="0" cellspacing="1" cellpadding="1">
<form name="form1" method="post" action="shopcar.jsp">
<tr><td align=center>
<input type="submit" name="clear" value="清空">
</td></tr>
</form>
</table>

<% } %>
</td>
</tr>

</table>

</td>
</tr>
</table>
<%@ include file="inc/date.inc"%>

为什么会报错:for input String "43.0" int totalint= Integer.parseInt((String)session.getAttribute("total"));
pay.pay("user1",1);

有什么错误吗
...全文
319 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kimmking 2007-05-17
  • 打赏
  • 举报
回复
Double.valueOf("43.0").intValue
kindwell 2007-05-17
  • 打赏
  • 举报
回复
我注意到下面这段代码是写到了最前面:
String submits = request.getParameter("payout");
if (submits!=null && !submits.equals(""))

{
int totalint= Integer.parseInt((String)session.getAttribute("total"));
pay.pay("user1",1);

}

所以我认为也许是由于在jsp中java程序顺序执行下来的时候,由于还没有
向session中放入“total”这个值,所以导致getAttribute返回null,从而
无法parseInt。
如果试着把session中的total初始化一下,也许会有用。
YUNYUN_033 2007-05-16
  • 打赏
  • 举报
回复
没有出现逗号,主要的代码是这边先for (int i=0; i<shoplist.size();i++){
allorder iList = (allorder) shoplist.elementAt(i);
if (book_list.getOnebook((int)iList.getBookNo())) {
book bk = (book) book_list.getBooklist().elementAt(0);
totalprice = totalprice + bk.getPrince() * iList.getAmount();
String total=String.valueOf(totalprice);//
session.setAttribute("total",total);//
totalamount = totalamount + iList.getAmount();//
%>

再String submits = request.getParameter("payout");
if (submits!=null && !submits.equals(""))

{
int totalint= Integer.parseInt((String)session.getAttribute("total"));//
pay.pay("user1",1);

}


kindwell 2007-05-16
  • 打赏
  • 举报
回复
数字向字符转化时出了错。看看得到的totalprice里面是不是有逗号之类的
分隔符导致无法转换成数字型。
YUNYUN_033 2007-05-16
  • 打赏
  • 举报
回复
numberformatexception
li_d_s 2007-05-16
  • 打赏
  • 举报
回复
最后的错误信息让人看不懂

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧