从一表单中用actionform取出数据设置类型为double型
<form .....>
<input type="text" name="value1">
<input type="text" name="value2">
...........
Actionform中如下:private doublel value1;
private double2 value2;
..........public void setValue1(double Value1){.........}public double getValue1(){    return value1;}
...........
编译是一切正常,但是当用getxx()方法从actionform 中取数据是去发生异常错误!没有注册getValue1()方法!
求救!!!!程序大概就是:
从一个表单中输入两个数据进行简单的运算,采用struts框架!当在actionform中定义为int类型的时候一切正常,但是当定义为double类型的时候getxx()方法发生错误!是否actionform中没有从string装换为double型的转换器!(用long型发生同样的错误)。

解决方案 »

  1.   

    多贴点出来看看,可以转化为double的
      

  2.   

    private doublel value1;
    private double2 value2;   
    double1,double2是什么类型?
      

  3.   

    <input type="text" name="value1">
    <input type="text" name="value2"> 
    对么?不用结束符的?private doublel value1;
    private double2 value2; 
    对么?struts1还是2?怎么又有actionForm又有转换器?
      

  4.   

    不要意思!那个写错了!
    是double型!我现在在机房!源码等下贴出来!
      

  5.   

    不好意思!电信那个垃圾!一直没网!
    <%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%><img src="pictures/logo5.bmp"></img>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>
    <p align="center">
    欢迎进入到微型计算器测试页面
    </p>
    <p align="center">
    <img alt="" src="pictures/00052.jpg">
    </p>
    </h1>
    <hr size="5" color="#15a06d" width="80%">
    <p>
    &nbsp;
    </p>
    <form action="result.do" method="get">
    <center>
    <input type="text" name="NO_1" size="12" maxlength="12">
    <select name="type">
    <option selected="selected">+</option>
    <option>-</option>
    <option>*</option>
    <option>/</option>
    </select>
    <input type="text" size="12" name="NO_2"  maxlength="12">
    <input type="submit" value="=">
    </center>
    </form> 
    <img alt="" src="pictures/00052.jpg"><img alt="" src="pictures/logo2.png"><br><br><br> </body>
    </html>Struts-config。xml配置如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
    <struts-config>
    <data-sources />
    <form-beans>
    <form-bean name="calform" type="com.longdpt.computer.computeractionForm"></form-bean>
    </form-beans>
    <global-exceptions />
    <global-forwards />
    <action-mappings>
    <action path="/result" type="com.longdpt.computer.computerAction"
    name="calform" input="jisuan.jsp" scope="request" attribute="calform">
    <forward name="success" path="/result.jsp"></forward>
    <forward name="failure" path="/errer.jsp"></forward>
    </action>
    <action path="/a" forward="/jisuan.jsp"></action>
    </action-mappings>
    <message-resources parameter="com.longdpt.computer.ApplicationResources" />
    </struts-config>
    actionform:如下package com.longdpt.computer;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;import com.sun.java_cup.internal.internal_error;public class computeractionForm extends ActionForm { /**
     * 
     */ private double NO_1;

    private double NO_2;
    private String type;
    public double getNO_1() {
    return NO_1;
    }
    public void setNO_1(double no_1) {
    NO_1 = no_1;
    }
    public double getNO_2() {
    return NO_2;
    }
    public void setNO_2(double no_2) {
    NO_2 = no_2;
    }
    public String getType() {
    return type;
    }
    public void setType(String type) {
    this.type = type;
    }

    }
    action如下:package com.longdpt.computer;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;import com.sun.java_cup.internal.internal_error;public class computerAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {


    /*
     * 取出表单数据
     */
    ActionForward forward =new ActionForward();
    double NO_3=0;
    try {


    computeractionForm form2 =(computeractionForm)form;


    double NO_1=form2.getNO_1();
    System.out.println("NO_1:"+NO_1);
    double NO_2=form2.getNO_2();
    String type=form2.getType();


    if ("+".equals(type)) {
    NO_3=NO_1+NO_2;
    System.out.println("NO_3:"+NO_3);
    forward =mapping.findForward("success"); 
    }else {
    forward=mapping.findForward("failure");
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    String result;
    result=(new Double(NO_3)).toString();
    System.out.println(result);
    request.setAttribute("result",result);
    return (forward);

    }}
    错误如下:
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoSuchMethodError: com.longdpt.computer.computeractionForm.getNO_1()I
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause javax.servlet.ServletException: java.lang.NoSuchMethodError: com.longdpt.computer.computeractionForm.getNO_1()I
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
    org.apache.jsp.result_jsp._jspService(result_jsp.java:95)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause java.lang.NoSuchMethodError: com.longdpt.computer.computeractionForm.getNO_1()I
    org.apache.jsp.result_jsp._jspService(result_jsp.java:71)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
    --------------------------------------------------------------------------------Apache Tomcat/6.0.20
      

  6.   

    个人感觉 这个问题好像是通过配置文件进行反射的时候出的错误,请检查 web.xml 及struts-config.xml文件的配置
      

  7.   

    感觉是setter和getter的变量命名规则错误了,把name="NO_1"改为name="no_1" name="NO_2"为name="no_2" private double no_1;
    private double no_2;
    private String type; public double getNo_1() {
    return no_1;
    }
    public void setNo_1(double no_1) {
    this.no_1 = no_1;
    }
    public double getNo_2() {
    return no_2;
    }
    public void setNo_2(double no_2) {
    this.no_2 = no_2;
    }
    public String getType() {
    return type;
    }
    public void setType(String type) {
    this.type = type;
      

  8.   

    刚帮你测了下,没问题!
    这是打印结果,我没建你的跳转结果页面:
    NO_1:10.0
    NO_3:20.0
    20.0
      

  9.   

    javax.servlet.ServletException: java.lang.NoSuchMethodError: com.longdpt.computer.computeractionForm.getNO_1()I 
    对于这个问题,你试着重启下服务器试试
      

  10.   

    NO_1,NO_2有问题,识别不了getNO_1()这个方法,把N改成n试试
      

  11.   

    我在myeclipse+tomcat6下试了,可以的
      

  12.   

    在ActionForm中定义属性时最好都定义成字符串类型的,再在后台进行转换比较好。
      

  13.   

    命名是没有问题的,只是说不符合规范而已,如果他变量的第二个字母是小写的话才会有问题。
    struts中字符串转基本类型应该是可以的,是不是jar包问题,我建议form中的成员变量都都定义成字符串比较好,要用到的时候,可以再后台通过API进行转换。还有一种比较好的设计:将一个功能中的表单信息都封装到一个类中,在ActionForm中只需要定义这个对象就行了。
    <html:text property="变量名.属性名" value=""/>这里的变量名是在ActionForm中的那个变量
      

  14.   

    呵呵,把NO_1改为no_1的确是没有问题了!但是为啥把NO_1定义为int性的时候为什么就没有问题,运行就一切正常呢!