大家好,我想从action里向jsp传递数组,总是出错。下面给出我的方法和结果,麻烦帮看看。实在着急了!action 层   country = new String[availableItems.size()];
   confcount = new Long[availableItems.size()];
   while(it.hasNext())
   {
      obj = (Object[])it.next();
      country[length] = (String)obj[0];
      confcount[length] = (Long)obj[1];
      length= length +1;
    }
   HttpServletRequest request = ServletActionContext.getRequest();
   request.setAttribute("country", country);
   return SUCCESS;
JSP层HttpServletRequest request1 = ServletActionContext.getRequest();
String[] country = request1.getParameterValues("country");
for(int i=0;i<country.length;i++)
{
  out.println(country[i]);
  out.println("<br>");
}
运行后提示for(int i=0;i<country.length;i++) 这排代码 org.apache.jasper.JasperException: An exception occurred processing JSP page /statistic/stabycountry.jsp at line 24
然后java.lang.NullPointerException我觉得是action的数组并没有传过来,就修改action代码的return为
return new ActionForward("/index.jsp");
但是定义actionforward需要定义action-mappings,我不知道在哪里定义大家帮看看,谢谢! 这已经是我能给的最高分了。

解决方案 »

  1.   

    但是定义actionforward需要定义action-mappings,我不知道在哪里定义?定义action-mappings是在struts的配置文件中配置(struts-config.xml)
      

  2.   

    看看这样行不行 String[] country =(String[])request.getAttribute("country");
      

  3.   

    JSP页面不用这样显式获取 request 对象  
    HttpServletRequest request1 = ServletActionContext.getRequest();jsp页面直接使用 request 对象获取传入的对象 
    String[] country =(String[])request.getAttribute("country");
      

  4.   

    大家好,问题解决了。String[] country = (String[])request1.getAttribute("country");这样就对了!给分结贴