我的bean用
注释@Component("Person")
@Scope(value="session", proxyMode = ScopedProxyMode.TARGET_CLASS)
我有一些getter和setter,但我有兴趣进入我的JSP是
@Transient
private ArrayList<DummyProduct> products = new ArrayList<DummyProduct>();
public ArrayList<DummyProduct> getProducts() {
return products;
}
public void setProducts(ArrayList<DummyProduct> products) {
this.products = products;
}
然后在我的控制器中,我将产品添加到该列表
DummyProduct prod = new DummyProduct(product);
this.person.getProducts().add(prod);
然后在我的JSP中我尝试了,没有运气来获得产品:
<table id="cart_table" border="1">
<tr>
<th>Product</th>
</tr>
<c:forEach var="prd" items="${sessionScope.Person.products}" >
<tr>
<td>${prd.productName}</td>
</tr>
</c:forEach>
</table>
我还使用了以下属性,以便我的bean暴露给jsps:<beans:property name="exposeContextBeansAsAttributes"
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<beans:property name="exposeContextBeansAsAttributes" value="true" />
编辑:控制器:
@org.springframework.stereotype.Controller
public class Controller {
@RequestMapping(value= "/addProduct", method = RequestMethod.POST)
public String addProduct(HttpServletRequest request, Map<String, Object> model, @RequestParam String product){
DummyProduct prod = new DummyProduct(product);
this.person.getProducts().add(prod);
return "loggedIn";
}
}
表格始终为空。我已经调试了,我在我的人bean中看到了产品列表的填充。
答案 0 :(得分:1)