通过控制器将购物车项目传递到另一个jsp页面

通过控制器将购物车项目传递到另一个jsp页面,jsp,spring-mvc,servlets,dispatcher,Jsp,Spring Mvc,Servlets,Dispatcher,我试图实现非常基本的购物车。我正在努力通过SpringMVCcontroller将项目从page1.jsp传递到page2.jsp。在上述控件的GET方法中,我有这些项,但它们没有显示在page2.jsp上。流看起来像这样 page1.jsp(签出)-->控制器(在GET方法中可以使用值)-->pag2.jsp(空) 这是控制器 @Controller @SessionAttributes("cart") public class CheckoutController { @Reque

我试图实现非常基本的购物车。我正在努力通过SpringMVCcontroller将项目从page1.jsp传递到page2.jsp。在上述控件的GET方法中,我有这些项,但它们没有显示在page2.jsp上。流看起来像这样

page1.jsp(签出)-->控制器(在GET方法中可以使用值)-->pag2.jsp(空)

这是控制器

@Controller
@SessionAttributes("cart")
public class CheckoutController 
{
    @RequestMapping( method = RequestMethod.GET)
    public ModelAndView ShowCheckoutMenu(@ModelAttribute("cart") ArrayList<Menu> mycart, Model model)                                   
    {
       // cart items available here. im adding them to the view
        return new ModelAndView("checkout_menu", "cart", mycart);
    }
}
@控制器
@会期贡献(“cart”)
公共类签出控制器
{
@RequestMapping(method=RequestMethod.GET)
公共模型和视图显示签出菜单(@modeldattribute(“cart”)ArrayList mycart,Model Model)
{
//购物车项目在此可用。我正在将它们添加到视图中
返回新模型和视图(“签出菜单”、“购物车”、“我的购物车”);
}
}
现在是page2.jsp

        <form:form modelAttribute="cart">
        <table>
            <tr>
                <th style="width:10%">Name</th>
                <th style="width:10%">Price Rs.</th>
                <td></td>
            </tr>    

            <c:set var="total_cost" value="0" scope="page" />
            <c:forEach items="${cart}" var="cart_item">
                <tr>
                    <c:choose> 
                      <c:when test="${fn:length(cart) gt 0}">
                        <td style="width:10%">${cart_item.getMenuName()}</td>
                        <td style="width:10%">${cart_item.getMenuPrice()}</td>
                        <c:set var="total_cost" value="${total_cost + cart_item.getMenuPrice()}" scope="page"/>
                      </c:when>
                      <c:otherwise>
                        <b><i>EMPTY LIST</i></b>
                      </c:otherwise>
                    </c:choose>                    
                </tr>
            </c:forEach>
            <tr>
                <td style="width:10%">Total Cost:</td>
                <td style="width:10%"><c:out value="${total_cost}" /></td>
            </tr>                
        </table>
    </form:form>

名称
价格卢比。
${cart\u item.getMenuame()}
${cart\u item.getMenuPrice()}
空列表
总成本:

现在,当显示page2.jsp时,它向我显示空列表,而正如我前面所说的,项目在控制器中,我将它们附加到视图中。这里怎么了???感谢您的输入。

尝试使用属性名而不是getter方法访问值。例如:我的意思是说尝试cart\u item.menuName而不是cart\u item.getMenuName()。而且你应该迭代mycart而不是cart。请检查一下。当你说model和view(“checkout\u菜单”,“cart”,mycart)时;第一个参数是视图名称,第二个参数是模型名称,第三个参数是模型对象。所以我想你应该使用模型对象来迭代