首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

struts结构 jsp得不到传值

2012-01-01 
求助 struts结构 jsp得不到传值各位大哥帮忙看一下问题在哪程序目的:jsp中接收Action的赋值。相关代码如下:

求助 struts结构 jsp得不到传值
各位大哥帮忙看一下问题在哪

程序目的:jsp中接收Action的赋值。相关代码如下:

1.AreaAction.java中赋值
Collection   coll   =   new   ArrayList();
coll   =   db.select(..);
if   (coll   ==   null   ||   coll.isEmpty())
{return   actionMapping.findForward( "fail ");
}else

{
request.setAttribute( "Area ",   coll);
return   actionMapping.findForward( "success ");
}

2.jsp4.jsp中获取   Area的值
<logic:iterate   id= "area "   name= "Area "   type= "com.cargo1.model.Area "   scope= "request ">
<tr   valign= "top "   bgcolor= "#FFFFFF ">
<td   height= "20 "   align= "center "   bgcolor= "#FFFFFF "> <bean:write   name= "area "   property= "name "   filter= "true "/> </td>
<td   height= "20 "   align= "center "   bgcolor= "#FFFFFF "> <bean:write   name= "area "   property= "resume "   filter= "true "/> </td>
</tr>
</logic:iterate>

3.struts-config.xml配置action-mapping

<action-mappings   type= "org.apache.struts.action.ActionMapping ">
<action   path= "/areaAction "   type= "com.cargo1.control.AreaAction "   validate= "false "   scope= "request ">
<forward   name= "success "   path= "/jsp4.jsp "   redirect= "true "   />
</action>

<action   path= "/areaAction "   type= "com.cargo1.control.AreaAction "   validate= "false ">
<forward   name= "fail "   path= "/jsp1.jsp "   redirect= "true "   />
</action>
</action-mappings>

问题:运行jsp4.jsp时从request中找不到Area,错误提示如下:
“javax.servlet.ServletException:   Cannot   find   bean   Area   in   scope   null”

那位大哥帮帮忙给小弟解释一下,万分感谢

[解决办法]
request.setAttribute( "Area ", coll);

<logic:iterate id= "area " name= "Area " >
<tr valign= "top " bgcolor= "#FFFFFF ">
<td height= "20 " align= "center " bgcolor= "#FFFFFF "> <bean:write name= "area " property= "name " filter= "true "/> </td>
<td height= "20 " align= "center " bgcolor= "#FFFFFF "> <bean:write name= "area " property= "resume " filter= "true "/> </td>
</tr>
</logic:iterate>


<action path= "/areaAction " type= "com.cargo1.control.AreaAction " validate= "false " scope= "request ">
<forward name= "success " path= "/jsp4.jsp " />
</action>

<action path= "/areaAction " type= "com.cargo1.control.AreaAction " validate= "false ">
<forward name= "fail " path= "/jsp1.jsp " />
</action>
[解决办法]
Collection coll = new ArrayList();
coll = db.select(..);
if (coll == null || coll.isEmpty())
{return actionMapping.findForward( "fail ");


}else

{
request.setAttribute( "Area ", coll);
return actionMapping.findForward( "success ");
}

2.jsp4.jsp中获取 Area的值
<logic:iterate id= "area " name= "Area " scope= "request ">
<tr valign= "top " bgcolor= "#FFFFFF ">
<td height= "20 " align= "center " bgcolor= "#FFFFFF "> <bean:write name= "area " property= "name " /> </td>
<td height= "20 " align= "center " bgcolor= "#FFFFFF "> <bean:write name= "area " property= "resume " /> </td>
</tr>
</logic:iterate>

3.struts-config.xml配置action-mapping

<action-mappings type= "org.apache.struts.action.ActionMapping ">
<action path= "/areaAction " type= "com.cargo1.control.AreaAction " validate= "false " scope= "request ">
<forward name= "success " path= "/jsp4.jsp " />
</action>

<action path= "/areaAction " type= "com.cargo1.control.AreaAction " validate= "false ">
<forward name= "fail " path= "/jsp1.jsp " />
</action>
</action-mappings>


你这么改

热点排行