如何显示我在会话中设置的bean数组?

时间:2017-05-10 14:30:19

标签: java arrays jsp

大家晚上好!我试图创建一个jsp页面,它将显示我在产品bean数组中设置的图像。下面是我的servlet:

String choice = request.getParameter("btn");
        HttpSession session = request.getSession(true);
        productBean[] product = new productBean[60];

        for (int i = 0; i < 30; i++){
            product[i] = new productBean();
            product[i].setImg("men" + " (" + (i+1) + ")");
            session.setAttribute(("product" + i), product[i]);
        }

        for (int i = 0; i < 30; i++){
            product[i+30] = new productBean();
            product[i+30].setImg("women" + "(" + (i+1) + ")");
            session.setAttribute(("product" + (i+30)), product[i+30]);
        }

        if ("Men".equals(choice)){
            request.getRequestDispatcher("brochureMen.jsp").forward(request,response);
        }
        else {
            request.getRequestDispatcher("brochureWomen.jsp").forward(request,response);
        }

以下是jsp:

<%
        String[] img = new String[30];
        for (int i = 0; i < 30; i++){
            session.getAttribute("product" + i);
            img[i] = product.getImg();
        }  
%>

<form action="showoutput.jsp" method="POST">
        <div class="container-fluid">

            <h2 class="text-center">For Lolos!</h2>
            <hr><br>
            <div class="row">
                <% for(int i = 0; i < 30; i++){ %>
                    <div class="col-md-4">
                        <center>
                            <h2><%= img[i] %></h2>
                            <button type="submit" value="<%= i %>" name="index">
                                <img src="<%= img[i] %>" class="img-responsive">
                            </button> 
                        </center>
                    </div>
                <% } %>
            </div>

        </div>
   </form>

我的问题是我的变量img数组没有存储任何东西。我错过了什么或做错了什么?它没有显示任何错误,所以我有点想法。谢谢!

0 个答案:

没有答案