(2)DiapacthAction

    DispatchAction用于分发的Action,主要的好处是把一些功能类似的Action放到一个Action中,通过传入的不同参数来觉得执行哪个操作.

  1. 创建一个类继承DispacthAction,该类中包含多个除方法名称以外其他都和execute()方法一样的多个方法

          public class OperateAction extends DispatchAction {
               public ActionForward add(ActionMapping mapping, ActionForm form,
               HttpServletRequest request, HttpServletResponse response)
               throws Exception {
               System.out.println("Action.add()");
               Cal c = new Cal();
               CalForm f =(CalForm)form;
               double r = 0.0;
               ActionMessages errors = new ActionMessages();
               try{
                     r = c.add(Double.parseDouble(f.getFirst()),Double.parseDouble(f.getSecond()));
               }catch(Exception e){
                     errors.add("num",new ActionMessage("error"));
                     this.saveErrors(request, errors);
                     return mapping.findForward("input");
              }
              f.setResult(r);
              return mapping.findForward("result");
        }
 public ActionForward sub(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  System.out.println("Action.sub()");
  return mapping.findForward("result");
 }
 public ActionForward mul(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  System.out.println("Action.mul()");
  return mapping.findForward("result");
 }
 public ActionForward div(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  System.out.println("Action.div()");
  return mapping.findForward("result");
 }
}

2. 在struts-config.xml文件中进行配置,为该Action配置parameter属性

   <action-mappings >
    <action
      name="CalForm"
      scope="request"
      path="/add"
      type="com.rhcj.struts.CalAction">
      <forward name="result" path="/result.jsp" />
    </action>
    <action path="/operate"
      type="com.rhcj.struts.OperateAction"
      name="CalForm"
      scope="request"
      parameter="operate">
      <forward name="result" path="/result.jsp" />
      <forward name="input" path="/index.jsp"></forward>
    </action>
   </action-mappings>

3.    创建页面,页面请求中要有一个参数与parameter属性值一致,如:/operate?operate=add,此处表单中使用隐藏域传值

   <input type="hidden" name="operate" value="">
    <input type="button" value="+" name="button1"
     οnclick="doSubmit('add')">
    <input type="button" value="-" name="button1"
     οnclick="doSubmit('sub')">
    <input type="button" value="*" name="button1"
     οnclick=doSubmit('mul');>
    <input type="button" value="/" name="button1"
     οnclick="doSubmit('div')">
    <script type="text/javascript">
     function doSubmit(oper){
      document.forms[0].elements["operate"].value=oper;
       document.forms[0].submit();
     }
    </script>

  

  

注意:该页面中隐藏域的name属性<input type="hidden" name="operate">对应于struts-config.xmlDispacthAction配置的parameter属性值

<action path="/operate"

        type="com.rhcj.struts.OperateAction"

        name="CalForm"

        scope="request"

        parameter="operate">

      <forward name="result" path="/result.jsp" />

</action>

隐藏域的value值要和DispacthAction中的方法名称对应

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智能核仪器己成为放射性测量仪器发展的一个主导方向,对应用核技术、国际核安全与武器核查、国防工程与科学试验等领域将产生极其深远的影响。作为一种核仪器——多道分析仪,主要应用在基于能谱分析的核测井,Y射线谱测量和X射线荧光测量。智能多道谱仪是多道分析仪的主要组成部分。 多道核能谱测量技术是用核方法进行物质成分分析和放射性检测的基础。论文瞄准国内外多道核能谱测量技术的发展趋势,针对目前现场多道核能谱测量仪器中存在的诸如仪器功耗、重量、体积偏大,不便于现场操作等问题,在多道脉冲幅度分析器以及仪器的单片机机化等方面作了较为系统的研究。论文对本人所研制的基于单片微机的现场多道核能谱数据采集系统作了较为详尽的论述。该系统在硬件上以单片机AT89C55为控制核心,以高速低功耗的A/D芯片MAX191 作为多道脉冲幅度分析器的模数转换器件,根据初步的性能测试,系统已经达到预期的设计目标。同时,为了实现人机交互,系统采用8279扩展了16键键盘。在系统的供电方面系统可采用充电电池供电。总体来说,系统采用按键输入,完成数据采集工作,除此之外,系统可通过RS-232C与其它计算机联机使用。软件系统采用了多种编程语言高级语言C语言和汇编混合编写,充分利用多种语言的混合编程技术以及不同语言的优点,在兼顾实时性处理的同时也能很方便地进行数据处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值