我有一个使用Session的Shopping Cart项目并将数据插入数据库。 我的showCart.jsp:
<html>
<body>
<h1>Shopping Cart Details</h1>
<table width=50%>
<tr><td>Item ID</td><td>Number of item in Shopping Cart</td></tr>
<%
java.util.Enumeration em = session.getAttributeNames();
for(;em.hasMoreElements();){
String id= em.nextElement().toString();
//get value from session object (see HttpSession)
String count=session.getAttribute(id).toString();
out.println("<tr>");
out.println("<td>"+id+"</td>");
out.println("<td>"+count+"</td>");
out.println("</tr>");
}
%>
</table>
<h2><a href="itemList.jsp">Items List</h2>
<br>
<h2><a href="checkout.jsp">Check-out</h2>
</body>
</html>
在我的showCart.jsp中,它负责获取用户请求的产品(addtoCart)并显示它。 在我的Checkout.jsp
中<%@page import="DAO.DAO_Product"%>
<%@page import="Entity.Product"%>
<html>
<body>
<h1>Checkout!</h1>
<%
DAO_Product dao = new DAO_Product();
int count = Integer.parseInt(request.getParameter("count"));
int id = Integer.parseInt("id");
Product pro = new Product(id,count);
int n = dao.addBill(pro);
if(n>0){
out.println("Your request has been approved");
}
session.invalidate();
%>
<h2><a href="itemList.jsp">New Shopping Cart</h2>
</body>
</html>
在checkout.jsp中,它将使会话无效并将数据插入数据库(客户请求的数据库)。我的问题是:我无法插入“count”参数,并抛出异常:
org.apache.jasper.JasperException: java.lang.NumberFormatException: null
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServlet Wrapper.java:548)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.jav a:471)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:454)
java.lang.Integer.parseInt(Integer.java:527)
org.apache.jsp.checkout_jsp._jspService(checkout_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.jav a:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
有什么想法解决我的问题吗?谢谢。