struts 2 - 将参数从一个页面传递到另一个页面

时间:2012-04-28 15:25:19

标签: java struts2

帮助需要使用Struts 2传递参数。

<action name="Hfddisp1" class="model.HfddispAction" method="fetch_addesc">
   <result  >model.HfddispAction?ad_ref_no=${ad_ref_no}</result> 
</action>

我的jsp是

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
   <head>
   </head>
<body>
   <h1> Iterator tag example 12</h1>
   <h3>Iterator with IteratorStatus 12</h3>
   <table>
      <tr class="even"> 
         <td><b>Ad_ref_no</b></td> 
         <td><b>Ad_title</b></td> 
      </tr> 
      <s:iterator value="hftbList" status="hftbListStatus">
      <tr>
  <s:if test="#hftbListStatus.even == true">
         <td style="background: #CCCCCC"><s:property value="ad_ref_no"  /> </td>
         <td style="background: #CCCCCC"><s:property value="ad_title" />  </td>
         <td  style="background: #CCCCCC">     
            <a href="<s:url action="Hfddisp1"/>">click here-1 </a>   
         </td>  
      </s:if>       
      <s:else>
         <td>
            <s:property value="ad_ref_no" />
         </td>
         <td>
            <s:property value="ad_title" />
         </td>
         <td >
            <a href="<s:url  action="Hfddisp2"/>
               <s:param name="ad_ref_no" value="%    {ad_ref_no}" />  ">
               click       here2
            </a>   
         </td>
      </s:else>
   </tr>
   </s:iterator>
   </table>

我得到的错误是:

消息:没有为动作模型定义结果.HdddispAction和结果大量的测试在这里我可以说它是什么

文件:file:/ E:/Web_workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Gshax/WEB-INF/classes/struts.xml

我在迭代器中获取数据但无法在另一页中显示它。

<--------qry is executed2hftb_add_master[ad_ref_no=huge volume of test goes here i can say what is it,email_address=null]
<--------qry is executed2huge volume of test goes here i can say what is it 
description successfully queried:1 huge volume of test goes here i can say what is it
Apr 26, 2012 12:07:04 PM org.apache.struts2.dispatcher.Dispatcher serviceAction
SEVERE: Could not find action or result

从第一页我得到的输出是

Ad_ref_no Ad_title 

12123120  i am the king but not sing  click here-1  
213421123  new test1  click here-2  
4150  Ad_title ........11:32:08  click here-1  
4152  Ad_title ........11:32:09  click here-2  
4153  Ad_title ........11:32:10  click here-1 

当我点击这里点击-1时,我收到上述错误 我所做的一切都是将ADF 4150用于行动并在另一页显示说明

1 个答案:

答案 0 :(得分:0)

使用Struts2网址和参数标签......

目前你有这个:<s:url action="Hfddisp2"/><s:param name="ad_ref_no" value="% {ad_ref_no}" />请注意,param标签没有嵌套在url标签内。

你可以这样写:<s:url action="Hfddisp2"><s:param name="ad_ref_no"/></s:url>

请注意,上面省略了param tags value属性,因为它默认解析所提供的名称。

使用变量的几个属性可以使事情更清晰:

<s:url var="myurl" action="Hfddisp2">
   <s:param name="ad_ref_no"/>
</s:url>

然后你需要的地方:

<s:property value="#myurl"/>

此外,您应该能够将当前网址中的所有参数都包含在新网址中:

<s:url action="Hfddisp2" includeParams="get"/> 

有关详细信息,请参阅标记参考http://struts.apache.org/2.3.1.2/docs/tag-reference.html