大家好,我想从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,我不知道在哪里定义大家帮看看,谢谢! 这已经是我能给的最高分了。
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,我不知道在哪里定义大家帮看看,谢谢! 这已经是我能给的最高分了。
解决方案 »
- struts2+Hibernate+Spring中 action的操作
- 我有了自己的域名,可以自己建服务器吗?
- 请问Struts2中package namespace不写和namespace="/"有区别吗
- 关于在WEBWORK2中做验证的问题
- 请教如何在一个EJB中调用其他jar包中的类
- CMP中datasourcemapping是干什么用的?
- 数据库的设计问题和ejb,请教!
- 一个关于hibernate的问题
- 求APPLET传对象(非参数)回SERVLET的代码
- spring+mybatis maven 项目的一个错误
- HTTP Status 404 - There is no Action mapped for namespace / and action name hell
- hql语句
HttpServletRequest request1 = ServletActionContext.getRequest();jsp页面直接使用 request 对象获取传入的对象
String[] country =(String[])request.getAttribute("country");