注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

云之南

风声,雨声,读书声,声声入耳;家事,国事,天下事,事事关心

 
 
 

日志

 
 
关于我

专业背景:计算机科学 研究方向与兴趣: JavaEE-Web软件开发, 生物信息学, 数据挖掘与机器学习, 智能信息系统 目前工作: 基因组, 转录组, NGS高通量数据分析, 生物数据挖掘, 植物系统发育和比较进化基因组学

网易考拉推荐

DispatchAction Request[/messageAction] does not contain handler parameter named 'method'. This may be caused by whitespace in the label text  

2009-04-19 23:06:04|  分类: java-j2ee |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

DispatchActio E org.apache.struts.actions.DispatchAction  Request[/messageAction] does not contain handler parameter named 'method'.  This may be caused by whitespace in the label text.
出现这个异常的原因是,jsp页面上配置了如下的句子:

 

第一种情况是:

    你可以忘记在struts-config.xml中设置parameter="method"参数了, 这个参数你可以随便用一个字符串,并且在JSP页面中,你可能忘记了

<input type=hidden name=method value="你要在继承DispatchAction超类的Action子类的方法"

这样就可以了,

第二种情况:你想在JSP页面中调用多个JAVASCRIPT方法,能通JAVASCRIPT方法去调用ACTION类的方法时,可能要采用下面的做法了:
 <%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html>
 <head>
  <title>JSP for DynaActionForm form</title>
  <script type="text/javascript">
  function add(form){
  
     form.action= form.action+"?operator=doAdd";
    //javascript:window.location.href='/calculator.do?operator=doAdd';
         form.submit();
  }
  
  
  function subtract(form){
  
   // javascript:window.location.href="/calculator.do?operator=doSubstract";
    form.action=form.action+"?operator=doSubtract";
  
         form.submit();
  }
  
  
  function multiply(form){
     form.action=form.action+"?operator=doMultiply";
        form.submit();
  }
  function divide(form){
     form.action=form.action+"?operator=doDivide";
         form.submit();
  }
  </script>
 </head>
 <body>
  <html:form action="/calculator.do" method="post">
   firstNumber : <html:text property="firstNumber" />
   <html:errors property="firstNumber" />
   <br />
   secondNumber : <html:text property="secondNumber" />
   <html:errors property="secondNumber" />
   <br />
   <!-- 没有国际化的,用的HTML的形式 name="operator"与struts-config.xml中的paramater="operator" 要相同 -->
   
   <input type=submit name="operator"   value="加法" onclick="add(this.form);return false;">
   <input type=submit  name="operator"  value="减法" onclick="subtract(this.form);return false;">
   <input type=submit   name="operator" value="乘法" onclick="multiply(this.form);return false;">
   <input type=submit      value="除法" onclick="divide(this.form);return false;">
   

   <!-- 国际化的,用的struts标签的形式    property="operator"与struts-config.xml中的paramater="operator" 要相同-->
   <html:submit property="operator"  onclick="add(this.form);return false;"><bean:message key="item.add" />
   </html:submit>
   <html:submit property="operator" onclick="subtract(this.form);return false;"><bean:message key="item.subtract" />
   </html:submit>
   <html:submit property="operator" onclick="multiply(this.form);return false;"><bean:message key="item.multiply" />
   </html:submit>
   <html:submit property="operator" onclick="divide(this.form);return false;"><bean:message key="item.divide" />
   </html:submit>
   <!-- 没有国际化的,用的struts标签的形式 -->
   <!--
   <html:submit property="operator" value="加" onclick="add(this.form);return false;">加</html:submit>
   <html:submit property="operator" value="减" onclick="subtract(this.form);return false;">减</html:submit>
   <html:submit property="operator" value="乘" onclick="multiply(this.form);return false;">乘</html:submit>
   <html:submit property="operator"  value="除" onclick="divide(this.form);return false;">除</html:submit>
   -->
  </html:form>
 </body>
</html>

 

struts-config.xml

<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="calculatorForm" type="org.apache.struts.action.DynaActionForm">
      <form-property name="secondNumber" type="java.lang.String" />
      <form-property name="firstNumber" type="java.lang.String" />
    </form-bean>

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="calculatorForm"
      input="/calculator.jsp"
      name="calculatorForm"
      parameter="operator"
      path="/calculator"
      scope="request"
      validate="true"
      type="com.cn.web.CalculatorAction">
      <forward name="result" path="/result.jsp" />
    </action>

  </action-mappings>

  <message-resources parameter="ApplicationResources" />
</struts-config>

Action类:

public class CalculatorAction extends DispatchAction {
 /*
  * Generated Methods
  */

 /**
  * Method execute
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 // 加法
 public ActionForward doAdd(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {

  DynaActionForm calculatorForm = (DynaActionForm) form;// TODO
                // Auto-generated
                // method stub
  String firstNumber = (String) calculatorForm.get("firstNumber");
  String secondNumber = (String) calculatorForm.get("secondNumber");

  double a = Double.parseDouble(firstNumber);
  double b = Double.parseDouble(secondNumber);
  CalculatorModel cal = new CalculatorModel();
  double calResult = cal.add(a, b);
  request.setAttribute("calculatorResult", calResult);
  return mapping.findForward("result");
 }

 public ActionForward doSubtract(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {

  DynaActionForm calculatorForm = (DynaActionForm) form;// TODO
                // Auto-generated
                // method stub

  String firstNumber = (String) calculatorForm.get("firstNumber");
  String secondNumber = (String) calculatorForm.get("secondNumber");

  double a = Double.parseDouble(firstNumber);
  double b = Double.parseDouble(secondNumber);
  CalculatorModel cal = new CalculatorModel();
  double calResult = cal.subtract(a, b);
  request.setAttribute("calculatorResult", calResult);
  return mapping.findForward("result");
 }

 public ActionForward doMultiply(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {

  DynaActionForm calculatorForm = (DynaActionForm) form;// TODO
                // Auto-generated
                // method stub
  String firstNumber = (String) calculatorForm.get("firstNumber");
  String secondNumber = (String) calculatorForm.get("secondNumber");

  double a = Double.parseDouble(firstNumber);
  double b = Double.parseDouble(secondNumber);
  CalculatorModel cal = new CalculatorModel();
  double calResult = cal.multiply(a, b);
  request.setAttribute("calculatorResult", calResult);
  return mapping.findForward("result");
 }

 public ActionForward doDivide(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {

  DynaActionForm calculatorForm = (DynaActionForm) form;// TODO
                // Auto-generated
                // method stub

  String firstNumber = (String) calculatorForm.get("firstNumber");
  String secondNumber = (String) calculatorForm.get("secondNumber");

  double a = Double.parseDouble(firstNumber);
  double b = Double.parseDouble(secondNumber);
  CalculatorModel cal = new CalculatorModel();
  double calResult = cal.divide(a, b);
  request.setAttribute("calculatorResult", calResult);
  return mapping.findForward("result");
 }

}

  评论这张
 
阅读(5253)| 评论(2)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016