日期:2014-05-18  浏览次数:20845 次

关于 Bean 的问题,很着急,请帮帮我。
错误描述
Cannot find any information on property 'Pwd' in a bean of type 'cn.myweb.test.vo.testvo'

form.jsp内容
<form name="form1" method="post" action="TestVOPost.jsp">
MID
<input type="text" name="MID">
Pwd
<input type="text" name="Pwd">
MailBox
<input type="text" name="MailBox">
<input type="submit" value="Go">
</form>

处理页面内容
<jsp:useBean id="tvo" scope="request" class="cn.myweb.test.vo.testvo"/>
<jsp:setProperty name="tvo" property="MID"/>
<jsp:setProperty name="tvo" property="Pwd"/>
<h1>MID:<jsp:getProperty name="tvo" property="MID"/></h1>
<%= tvo.getPwd()%>

testvo.java的内容
package cn.myweb.test.vo;

public class testvo
{
  private String MID ;
  private String Pwd ;
  private String MailBox ;

  public testvo()
  {
  // 必须的无参构造
  }

  public String getMID()
  {
  return this.MID ;
  }
  public void setMID(String mid)
  {
  this.MID = mid ;
  }
  public String getPwd()
  {
  return this.Pwd ;
  }
  public void setPwd(String pwd)
  {
  this.Pwd = pwd ;
  }
  public String getMailBox()
  {
  return this.MailBox ;
  }
  public void setMailBox(String mailbox)
  {
  this.MailBox = mailbox ;
  }
}

怎么会找不到呢??

------解决方案--------------------
你方法中的参数名不同,不需要用this,Java是区分大小写的,这样改也成:

public String getMID() 

return this.MID ; 

public void setMID(String Mid) 

this.MID = Mid ; 

public String getPwd() 

return this.Pwd ; 

public void setPwd(String Pwd) 

this.Pwd = Pwd ; 

public String getMailBox() 

return this.MailBox ; 

public void setMailBox(String MailBox) 

this.MailBox = MailBox ; 


------解决方案--------------------
.jsp
<input type="text" name="pwd" > 

.java
private String pwd ;
 
public String getPwd()
{
return this.pwd ;
}
public void setPwd(String pwd)
{
this.pwd = pwd ;
}

提案:名子定義、第一個字母用小写