JSP和JAVABEAN问题

<%if("send".equals(request.getParameter("send"))){orderBean.setUserID(session.getValu... <%
if ("send".equals(request.getParameter("send")))
{
orderBean.setUserID(session.getValue("memberID"));
String str=request.getParameter("receivername");
orderBean.setReceiverName(str==null?"":str);
str=request.getParameter("orderprice");
orderBean.setOrderprice(java.lang.Float.valueOf(str==null?"0":str).floatValue());
str=request.getParameter("address");
orderBean.setReceiverAddress(str==null?"":str);
str=request.getParameter("postcode");
orderBean.setReceiverZip(str==null?"":str);
str=request.getParameter("bookinfo");
orderBean.setBookinfo(str==null?"":str);
str=request.getParameter("memo");
orderBean.setMemo(str==null?"":str);

int orderID=orderBean.getOrderID();
if (orderID>0)
{ /*清空Cookie(购物车)信息*/
Cookie[] cookies=request.getCookies();
for (int i=0;i<cookies.length;i++)
{ String isbn=cookies[i].getName();
if (isbn.startsWith("ISBN")&&isbn.length()==8)
{ Cookie c=new Cookie(isbn,"0");
c.setMaxAge(0);//设定Cookie立即失效
response.addCookie(c);
}
}
%>
<p align="center">订购成功!</p>
<p align="center"> 订单号:<%=orderID%></p>
<p align="center"><a href="booklist.jsp">返回首页</a></p>
<%
}
else
{
out.print("订购失败\n");

}
}

else
{ float price=0;
String bookInfo="";

%>

setUserID报错The method setUserID(String) in the type OrderBean is not applicable for the arguments (Object)
setOrderprice报错The method setOrderprice(String) in the type OrderBean is not applicable for the arguments (float)
还是有错,干脆哪位达人留下邮箱,我把OrderBean.java和order.jsp文件都发过去,帮我改下咯。3Q
展开
 我来答
老天爷不知道
2009-06-04 · TA获得超过167个赞
知道答主
回答量:131
采纳率:0%
帮助的人:67.4万
展开全部
1.关于setUserID报错The method setUserID(String) in the type OrderBean is not applicable for the arguments (Object)
其实很简单,你可以看一下HttpSession的API文档,getValue方法返回的是哟个Object类型,你可以把返回值进行强制类型转换,如:getValue((String)session.getValue("memberID")),这样比较安全,如果单纯使用session.getValue("memberID").toString()有可能会导致NullPointerException.

2.关于setOrderprice报错The method setOrderprice(String) in the type OrderBean is not applicable for the arguments (float)
其实很简单,说明setOrderprice方法的参数应该是String类型,你可以使用orderBean.setOrderprice(Float.toString(Float.parseFloat(str==null?"0":str)));
就可以了

修改后的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page language="Java" contentType="text/html;charset=GB2312"%>
<jsp:useBean class="cuug.BookBean" id="bookinfo" scope="page"></jsp:useBean>
<jsp:useBean class="cuug.OrderBean" id="orderBean" scope="page"></jsp:useBean>
<%
/*禁止使用浏览器Cache,网页立即失效*/
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires",0);
%>
<HTML>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>
填写订单
</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<%
if ("send".equals(request.getParameter("send")))
{
orderBean.setUserID((String)session.getValue("memberID"));
String str=request.getParameter("receivername");
orderBean.setReceiverName(str);
str=request.getParameter("orderprice");
orderBean.setOrderprice(Float.toString(Float.parseFloat(str)));
str=request.getParameter("address");
orderBean.setReceiverAddress(str);
str=request.getParameter("postcode");
orderBean.setReceiverZip(str);
str=request.getParameter("bookinfo");
orderBean.setBookinfo(str);

int orderID=Integer.parseInt(orderBean.getOrderID());

if (orderID>0)
{ /*清空Cookie(购物车)信息*/
Cookie[] cookies=request.getCookies();
for (int i=0;i<cookies.length;i++)
{ String isbn=cookies[i].getName();
if (isbn.startsWith("ISBN")&&isbn.length()==8)
{ Cookie c=new Cookie(isbn,"0");
c.setMaxAge(0);//设定Cookie立即失效
response.addCookie(c);
}
}
%>
<p align="center">订购成功!</p>
<p align="center"> 订单号:<%=orderID%></p>
<p align="center"><a href="booklist.jsp">返回首页</a></p>
<%
}
else
{
out.print("订购失败\n");

}
}

else
{ float price=0;
String bookInfoStr="";

%>
<FORM method="post" name="frm">
<TABLE border="1" width="100%" cellspacing="0" bordercolor="#9999FF">
<TR>
<TD width="90">ISBN</TD>
<TD width="269">书名</TD>
<TD width="50">单价</TD>
<TD width="75">数量</TD>
<TD width="48">价格 </TD>
</TR>
<% /*读取购物车信息*/
Cookie[] cookies=request.getCookies();
for (int i=0;i<cookies.length;i++)
{ String isbn=cookies[i].getName();
String num=cookies[i].getValue();
if (isbn.startsWith("ISBN")&&isbn.length()==8)
{
bookinfo.setBookISBN(isbn.substring(4,8));
Float bookPrice = new Float(bookinfo.getPrice());
%>
<TR>
<TD width="90"><%= bookinfo.getBookISBN()%></TD>
<TD width="269"><A href="bookinfo.jsp?isbn=<%= bookinfo.getBookISBN()%>"><%= bookinfo.getBookName()%></A></TD>
<TD width="50"><%= bookPrice%></TD>
<TD width="75">
<INPUT size="5" type="text" maxlength="5" value="<%= num%>" name="num" readonly></TD>
<TD width="48"><%= bookPrice.floatValue()*java.lang.Integer.parseInt(num)%></TD>
</TR>

<%
price += bookPrice.floatValue()*java.lang.Integer.parseInt(num);
bookInfoStr += bookinfo.getBookISBN()+"="+num+";";

}

}
%>
</TABLE>
<p> </p>
<table width="100%" border="0">
<tr>
<td width="34%"> </td>
<td width="41%">
<div align="center"><a href="shoppingcart.jsp">修改图书订单</a></div>
</td>
<td width="25%"> </td>
</tr>
</table>
<p><font color="#0000FF">如以上信息无误,请填写以下信息并按提交按钮提交订单,完成网上订书:</font></p>
<table width="100%" border="0">
<tr>
<td width="17%"><font color="#0000FF">收书人姓名</font></td>
<td width="83%">
<input type="text" name="receivername" size="10" maxlength="10">
</td>
</tr>
<tr>
<td width="17%"><font color="#0000FF">订单总金额</font></td>
<td width="83%">
<input type="text" name="orderprice" size="10" value="<%=price%>" readonly>
</td>
</tr>
<tr>
<td width="17%"><font color="#0000FF">发送地址</font></td>
<td width="83%">
<input type="text" name="address" size="60" maxlength="60">
</td>
</tr>
<tr>
<td width="17%"><font color="#0000FF">邮编</font></td>
<td width="83%">
<input type="text" name="postcode" size="6" maxlength="6">
</td>
</tr>
<tr>
<td width="17%"><font color="#0000FF">备注</font></td>
<td width="83%">
<textarea name="memo" cols="60" rows="6"></textarea>
</td>
</tr>
<tr>
<td width="17%"><font color="#0000FF"></font></td>
<td width="83%">
<input type="submit" name="Submit" value="提交订单">
<input type="hidden" name="send" value="send">
<input type="hidden" name="bookInfo" value="<%= bookInfoStr%>">
</td>
</tr>
</table>
</FORM>
<%
}
%>
</BODY>
</HTML>
yi88cheng
2009-06-02 · TA获得超过121个赞
知道小有建树答主
回答量:181
采纳率:0%
帮助的人:124万
展开全部
orderBean.setUserID(session.getValue("memberID"));
session.getValue("memberID")取出的是对象 不是 整形的
如果你的是 String类型的orderBean.setUserID(session.toString());
如果你的是int类型的
orderBean.setUserID(Integer.parseInt(session.toString()));
也是一样 setOrderPrice 看看是否是float类型的
orderBean.setOrderprice(java.lang.Float.valueOf(str==null?"0":str).floatValue());
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
幸叶孤帆nM
2009-06-03
知道答主
回答量:36
采纳率:0%
帮助的人:25.3万
展开全部
session里取出的值是object,需要强制转换成String
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式