doshop.jsp<body>
   <%
     String goodsName=request.getParameter("goods");
     if(!goodsName.equals("")){
       goodsName=new String(goodsName.getBytes("ISO-8859-1"),"gb2312");
       ArrayList list=null;
       list=(ArrayList)session.getAttribute("list");
       if(list==null){
         list=new ArrayList();
         list.add(goodsName);
         session.setAttribute("list",list);
                      }
        else
         {
           list.add(goodsName);
          }
     %>
    <br><center>
      <strong>提示:您刚才选择了商品 <font color="red"><%=goodsName%>
      </font>,请问您还想做什么?</strong> <br><br>
      <button onclick="location.href='shop.jsp'">继续购买</button>
      <button onclick="location.href='pay.jsp'">结账</button>
   </center>
  <%}else{
  response.sendRedirect("shop.jsp");
      }
   %>
</body>

解决方案 »

  1.   

    String goodsName=request.getParameter("goods");
      if(goodsName !=null && !goodsName.equals("")){
      

  2.   

    list=(ArrayList)session.getAttribute("list");如果session.getAttribute("list")为空就会报错
      

  3.   

    String goodsName=request.getParameter("goods");
    //应该判断一下:
    if(goodsName!=null&&!goodsName.Trim().equals(""))
    {
        //添加你的代码
    }
      

  4.   

    这页面根本打开不了HTTP Status 500 
    我从shop.jsp中输入商品名称,点确定就转到以上doshop.jsp页面,但页面根本打开不了HTTP Status 500 
      

  5.   

    shop.jsp代码为:<form name="form1" method="post" action="doshop.jsp">
      <div align="left">
        <table width="100%" border="0" cellspacing="5">
          <tr><td><p>请选择要购买的商品:
               <input type="text" name="goods">
               <input type="submit" name="Submit" value="提交">
             </p></td></tr>
        </table>
      </div>
    </form>
      

  6.   

    很奇怪,我用你的代码创建了两个jsp文件:shop.jsp和 doshop.jsp,
    然后在浏览器里运行,没有出现过错误,一切都可能运行的,然后在命令行里打印出list的内容,也是可以的:
    这个是list里输入的内容:[hello, ok, gu]500错误一般都是数据的格式解析出错,可能是程序的其他地方错了?1. shop.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form name="form1" method="post" action="doshop.jsp">
    <div align="left">
    <table width="100%" border="0" cellspacing="5">
    <tr>
    <td>
    <p>请选择要购买的商品: <input type="text" name="goods"> <input
    type="submit" name="Submit" value="提交"></p>
    </td>
    </tr>
    </table>
    </div>
    </form>
    </body>
    </html>2. doshop.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.util.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
        String goodsName = request.getParameter("goods");
        if (!goodsName.equals("")) {
            goodsName = new String(goodsName.getBytes("ISO-8859-1"), "gb2312");
            ArrayList list = null;
            list = (ArrayList) session.getAttribute("list");
            if (list == null) {
                list = new ArrayList();
                list.add(goodsName);
                session.setAttribute("list", list);
            } else {
                list.add(goodsName);
            }
            System.out.println(list);
    %>
    <br>
    <center><strong>提示:您刚才选择了商品 <font color="red"><%=goodsName%>
    </font>,请问您还想做什么?</strong> <br>
    <br>
    <button onclick="location.href='shop.jsp'">继续购买</button>
    <button onclick="location.href='pay.jsp'">结账</button>
    </center>
    <%
        } else {
            response.sendRedirect("shop.jsp");
        }
    %>
    </body>
    </html>