JSP为什么点加入购物车就出现500错误?
页面代码:<tdalign="center"width="70"><ahref="AddCDToCart?id=<%=CD.getCDID()%>"onClick="wi...
页面代码: <td align="center" width="70"><a href="AddCDToCart?id=<%=CD.getCDID()%>"
onClick="window.open('Cart.jsp?id=<%=CD.getCDID()%>','Cart','width=580,height=360,resizable=no,scrollbars=yes')">
<a href="AddCDToCart?id=<%=CD.getCDID()%>"><img src="images/BUY.gif" border=0 alt=""></a></td>
servlet代码: public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
User user = (User) session.getAttribute("LoginUser");
Map cart = (Map) session.getAttribute("cart");
int CDID;
try {
CDID = Integer.parseInt(request.getParameter("CDID"));
}
catch (Exception ex) {
CDID = 0;
}
System.out.println("CDID是:"+CDID) ;
if (user == null) {
out.println("<script type=\"text/javascript\">");
out.println("alert(\"您还未登录,请先登录!\")");
out.println("window.open(\"login.jsp\",\"_self\")");
out.println("</script>");
return;
}
else
if (cart == null) {
cart = new HashMap();
}
try {
CDDAO dao = new CDDAO();
CD CD = dao.findCD(CDID);
Cart ct = (Cart) cart.get(String.valueOf(CDID));
if (ct == null) {
ct = new Cart(CD);
}
else {
ct.setNumber(ct.getNumber() + 1);
}
cart.put(String.valueOf(CDID), ct);
session.setAttribute("cart", cart);
RequestDispatcher rd = request.getRequestDispatcher("Cart.jsp");
rd.forward(request, response);
}
catch (Exception ex) {
ex.printStackTrace();
}
out.close();
问题补充:就是 HTTP Status 404 - /shopModule/AddCDToCart
--------------------------------------------------------------------------------
type Status report
message /shopModule/AddCDToCart
description The requested resource (/shopModule/AddCDToCart) is not available.
啊
AddCDToCart是在web.xml里有写的 就叫这个名字啊 展开
onClick="window.open('Cart.jsp?id=<%=CD.getCDID()%>','Cart','width=580,height=360,resizable=no,scrollbars=yes')">
<a href="AddCDToCart?id=<%=CD.getCDID()%>"><img src="images/BUY.gif" border=0 alt=""></a></td>
servlet代码: public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
User user = (User) session.getAttribute("LoginUser");
Map cart = (Map) session.getAttribute("cart");
int CDID;
try {
CDID = Integer.parseInt(request.getParameter("CDID"));
}
catch (Exception ex) {
CDID = 0;
}
System.out.println("CDID是:"+CDID) ;
if (user == null) {
out.println("<script type=\"text/javascript\">");
out.println("alert(\"您还未登录,请先登录!\")");
out.println("window.open(\"login.jsp\",\"_self\")");
out.println("</script>");
return;
}
else
if (cart == null) {
cart = new HashMap();
}
try {
CDDAO dao = new CDDAO();
CD CD = dao.findCD(CDID);
Cart ct = (Cart) cart.get(String.valueOf(CDID));
if (ct == null) {
ct = new Cart(CD);
}
else {
ct.setNumber(ct.getNumber() + 1);
}
cart.put(String.valueOf(CDID), ct);
session.setAttribute("cart", cart);
RequestDispatcher rd = request.getRequestDispatcher("Cart.jsp");
rd.forward(request, response);
}
catch (Exception ex) {
ex.printStackTrace();
}
out.close();
问题补充:就是 HTTP Status 404 - /shopModule/AddCDToCart
--------------------------------------------------------------------------------
type Status report
message /shopModule/AddCDToCart
description The requested resource (/shopModule/AddCDToCart) is not available.
啊
AddCDToCart是在web.xml里有写的 就叫这个名字啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询