一个页面多个提交按钮

 

<html>
<head>
<%if(request.getAttribute("msg")!=null){%>
  <script>
     alert("<%=request.getAttribute("msg")%>");
  </script>
<%}%>
</head>

<body>
<html:form action="/test.shtml?action=list" method="post">
<table>
   <input name ="submit1" type="button" value="查询" οnclick="clickBtn(1)"/>
   <input name ="submit2" type="button" value="添加" οnclick="clickBtn(2)"/>
   <input name ="submit3" type="button" value="删除" οnclick="clickBtn(3)"/>
</table>
<table>
   <tr>
       <td align="center" valign="middle" bgcolor="#DDEEF8" nowrap class="tb27">编号</td>
         <td align="center" valign="middle" bgcolor="#DDEEF8" nowrap class="tb29">名称</td>          
   </tr>
   <tr>
      <logic:notEmpty name="rs" >
       <logic:iterate name="rs" id="itm">
       <td align="center" valign="middle" class="tb27">&nbsp;<bean:write name="itm" property="userno"/></td>
         <td align="center" valign="middle" class="tb29">&nbsp;<bean:write name="itm" property="username"/></td>
       </logic:iterate>
      </logic:notEmpty>
   </tr>
</table>
</html:form>
</body>
<html>

<script language="javascript">
  function clickBtn(no){
    if(no==1){
      document.forms[0].action="/test/test.shtml?action=list";
    }else if (no==2){
      document.forms[0].action="/test/test.shtml?action=add";
    }else if (no==3){
      document.forms[0].action="/test/test.shtml?action=del";
    }
    document.forms[0].submit();
  }
</script>
 

 

=========================Action=========================

public class TestAction extends DispatchAction {
  public ActionForward add(ActionMapping mapping,ActionForm form,
      HttpServletRequest request,HttpServletResponse response){
       String msg="";
       TestDao dao=new TestDao();
       if(dao.add()==true){
        msg="添加成功!";              //这个传到页面用
       }else{
        msg="添加失败";
       }
       request.setAttribute("msg",msg);
       return mapping.findForward("list");
      }
}


=====================struts-config.xml==================
<action-mapping>
 <action name="testForm" path="/test" scope="request"
 parameter="action" type="******.action.TestAction">
 <forward name="index" path="/index.jsp">
 <forward name="list"  path="/test.shmt?action=list"/> //注意这个地方 可以进行跳转(页面的功能相同)
</action-mapping>

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值