将 arraylist 从 servlet 发送到 jsp 时显示错误
Showing error while sending arraylist from servlet to jsp
我想将 ArrayList 对象从 servlet 页面发送到 jsp page.But jsp 页面中显示错误。
下面是我的servlet代码
Servlet
ArrayList<Customer> al = new ArrayList<Customer>();
al = abs.viewCustomerReqRequest();
//Return type of viewCustomerReqRequest() method is ArrayList<Customer>
request.setAttribute("Customer_AL",al);
RequestDispatcher rd = request.getRequestDispatcher("a_reg_request.jsp");
rd.forward(request, response);
下面是我的jsp页面代码
JSP
<%
ArrayList<Customer> al = new ArrayList<Customer>();
al = (ArrayList<Customer>) request.getAttribute("Customer_AL");
Iterator<Customer> it = al.iterator();
%>
但是在我的 jsp 页面中显示了类似“类型安全:未检查的从对象到 ArrayList<Customer>
”的错误。
如何从我的 jsp 页面中删除此错误?
ServletRequest.setAttribute()
的第二个参数是 Object
类型。
一旦将 List
作为 Object
参数传递,它就会丢失编译时类型。警告会告诉您这一点。但这是警告,不是错误。
如果你想抑制警告,你可以使用
@SuppressWarnings("unchecked")
al = (ArrayList<Customer>) request.getAttribute("Customer_AL");
我想将 ArrayList 对象从 servlet 页面发送到 jsp page.But jsp 页面中显示错误。
下面是我的servlet代码
Servlet
ArrayList<Customer> al = new ArrayList<Customer>();
al = abs.viewCustomerReqRequest();
//Return type of viewCustomerReqRequest() method is ArrayList<Customer>
request.setAttribute("Customer_AL",al);
RequestDispatcher rd = request.getRequestDispatcher("a_reg_request.jsp");
rd.forward(request, response);
下面是我的jsp页面代码
JSP
<%
ArrayList<Customer> al = new ArrayList<Customer>();
al = (ArrayList<Customer>) request.getAttribute("Customer_AL");
Iterator<Customer> it = al.iterator();
%>
但是在我的 jsp 页面中显示了类似“类型安全:未检查的从对象到 ArrayList<Customer>
”的错误。
如何从我的 jsp 页面中删除此错误?
ServletRequest.setAttribute()
的第二个参数是 Object
类型。
一旦将 List
作为 Object
参数传递,它就会丢失编译时类型。警告会告诉您这一点。但这是警告,不是错误。
如果你想抑制警告,你可以使用
@SuppressWarnings("unchecked")
al = (ArrayList<Customer>) request.getAttribute("Customer_AL");