在action里面根据按钮的值来判断点击了那个按钮

解决方案 »

  1.   

    当有多个提交按钮时,可采用Button按钮,一般是用JavaScript处理成所需要的提交格式,再进行提交,这些实现方法本身与Struts无关。具体的做法网上有许多资料和例子。
      

  2.   

    1:button
    <tr>
         <td colspan = "14" align = "right" >
      <input name = "Button2" type = "button" class = "ListButton" onClick = "set('add')" value = "新增">
      <input name = "Button2" type = "button" class = "ListButton" onClick = "set('modify')" value = "修改">
      <input name = "Button2" type = "button" class = "ListButton" onClick = "set('delete')" value = "删除">
     </td>
    </tr>2:javascript
    function set(method){
     if(method == 'modify'||method ==  'delete'){
      if(validate()){
      form1.method.value = method;
      form1.submit();
      }else{
        alert("至少选择一条记录");
      }
     }else{
       form1.method.value = method;
       form1.submit();
     }
       }3:form这样写:
    <form method = "post" name = "form1" action = "/fetchReceiptsAction.do" >
     <input type = 'hidden' name = 'method' >
      

  3.   

    从界面(a),使用dispatch(b),转发到另外一个action(c)之后,那么(c)能得到(a)的表单吗? 
      

  4.   

    如果像下面这样行吗?他是怎么得到值的呢?
    <html:form action="/ChoiceAction">
        <TABLE border="0" width="100%">
            <TR>
               <TD align="right">
                  <html:submit property="method">
                      <bean:message key="button.pathone"/>
                  </html:submit>
               </TD>
               <TD align="right">
                  <html:submit property="method">
                      <bean:message key="button.pathtwo"/>
                  </html:submit>
               </TD>
               <TD align="right">
                  <html:submit property="method">
                      <bean:message key="button.paththree"/>
                  </html:submit>
               </TD>
            </TR>
        </TABLE>
    </html:form>
    public class ChoiceAction extends LookupDispatchAction { // --------------------------------------------------------- Instance Variables // --------------------------------------------------------- Methods    public ActionForward path_one(ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response)
            throws IOException, ServletException
        {        return (mapping.findForward("choice_one"));
        }    public ActionForward path_two(ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response)
            throws IOException, ServletException
        {        return (mapping.findForward("choice_two"));
        }    public ActionForward path_three(ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response)
            throws IOException, ServletException
        {        return (mapping.findForward("choice_three"));
        }
        protected Map getKeyMethodMap()
        {
            Map map = new HashMap();
            map.put("button.pathone", "path_one");
            map.put("button.pathtwo", "path_two");
            map.put("button.paththree", "path_three");
      
            return(map);
        }}
      

  5.   

    不管你用多少个form,显然,一次只能提交一个表单,如果没有为name属性指定值,它将通过使用action 属性值查询相应的actionMapping 元素来计算,在这里表单bean名被确定。换句话说,如果没有为form标记指定name属性,标记符将使用配置文件的action元素中name属性值。这点非常重要。