request.getParameter()是获得通过get或者post获得来的数据,类型只能是String,不能cast成List
getAttribute()是之前自己设定的,类型可以是多种
比如request.setAttribute("name","小强");
然后另一页面
String name=request.getAttribute("name");
name就是小强喽
Attribute用作servlet向jsp传参,不限对象类型
servlet代码:
List<Map<String, Object>> list = service.listProduct(proname, start, end); request.setAttribute("listproduct", list); request.getRequestDispatcher("/product.jsp").forward(request, response);
jsp代码:
<% String path = request.getContextPath();List<Map<String, Object>> list = (List<Map<String, Object>>)request.getAttribute("listproduct"); %>
Done!