我已经搜索了很多,但是找不到我的错误。我有一个servlet并尝试将ArrayList放入bean中:
ClientBean c = new ClientBean();
c.setList(ClientsHandler.getAllClients());
request.setAttribute("listClients", c);
RequestDispatcher dispatcher = request.getRequestDispatcher("showClients.jsp");
dispatcher.forward(request, response);
在“ showClients.jsp”中,我尝试打印客户端的电话1:
<jsp:useBean id="listClients" class="beans.ClientBean" scope="request"/>
<% ArrayList<ClientsRowGateway> list = ((beans.ClientBean)request.getAttribute("listClients")).getList(); %>
<% out.println( ""+list.get(1).getPhone() ); %>
但是我有一个NullPointerException,因为我的对象列表为null。我怎样才能访问Bean内ArrayList内的object(Client)内的变量(getPhone())?
经过更多测试后,我尝试不使用Bean直接访问我的ArrayList并工作,打印客户端电话!
<%
ArrayList<ClientsRowGateway> testList = ClientsHandler.getAllClients();
if( testList != null )
out.println( testList.get(1).getPhone() );
%>
但是我需要使用一个bean,我只是做一个测试,所以有人可以帮助我吗?
检查您是否正在加载正确的.jars。通常,对于这种东西,您需要一些特定的jar才能在服务器上运行JSP / servlet。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句