问题描述
下面的程序错在那里了呀那位高手给分析解决一下呀程序是index.jsp的代码是<%@pagelanguage="java"import="java.util.*"pageEncoding="gb2312"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'index.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body><jsp:useBeanid="pb"class="pa.Pwbean"scope="page"></jsp:useBean><%pb.setPwNum(6);%><%--jsp:setPropertyproperty="pwdNum"name="pb"value="6"/--%><%pb.createPassword();%><h3>自动生成的随机密码位数为:</h3><jsp:getPropertyproperty="pwdNum"name="pb"/><h3>自动生成的密码为:</h3><jsp:getPropertyproperty="password"name="pb"/></body></html>javabean中的程序是packagepa;publicclassPwbean{privateintpwdNum;privatelongpassword;publicPwbean(){}publicvoidsetPwNum(intn){if(n<6){pwdNum=n;}else{pwdNum=6;}}publicintgetPwdNum(){returnpwdNum;}publicvoidcreatePassword(){doubled=Math.random();intn=1;for(inti=0;i<pwdNum;i++){n=n*10;}password=(long)(d*n);}publiclonggetPassword(){returnthis.password;}}然后就报了Can'tfindamethodtowriteproperty'pwdNum'oftype'int'inabeanoftype'pa.Pwbean'的错了
解决方案
解决方案二:
publicvoidsetPwNum(intn)写错了改成:publicvoidsetPwdNum(intn)
解决方案三:
bean里的字段get、set方法不全get、set方法可以自动生成。
解决方案四:
引用楼主zhmq19900808的回复:
下面的程序错在那里了呀那位高手给分析解决一下呀程序是index.jsp的代码是<%@pagelanguage="java"import="java.util.*"pageEncoding="gb2312"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme(……
正解
解决方案五:
引用出错了引用1楼runer的回复:
publicvoidsetPwNum(intn)写错了改成:publicvoidsetPwdNum(intn)
这是正解