【问题标题】:No getter method for property没有属性的getter方法
【发布时间】:2012-09-30 21:48:16
【问题描述】:

嗨,我正在尝试使用 struts 为我的 jsp 代码获取一个 bean,我在我的 jsp 页面中使用的 bean 是:但是每当我运行 jsp 时,我都会收到

没有属性的getter方法:bean的“testData.team.type”:“unitForm”。

我正在尝试将棒球写入我的 JSP 页面。

我的动作表单的代码是:

import com.TestGettingData;
import org.apache.struts.action.ActionForm;
public class UnitForm extends ActionForm {

private TestGettingData testData = new TestGettingData();  

public TestGettingData getTestData() {
    return testData;
}

public void setTestData(TestGettingData testData) {
    this.testData = testData;
} 

}

测试数据类有:

public class TestGettingData extends Sport{

    private String team = "Yankees"; 

private String position = "short stop";  

public void setTeam(String tm) {    
    team = tm; } 

public String getTeam() {     
        return team; } 

public void setPosition(String po) {    
    position = po; } 

public String getPosition() {   
    return position; 
    } 
}

最后在我的体育课上:

public class Sport{

    public String type = "baseball";

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}


}

【问题讨论】:

  • 你能在你的 JSP 中添加你正在做的事情吗?
  • 在 jsp 中我有: 这是一个数据测试:${unitForm.testData.type}

标签: java jsp object struts


【解决方案1】:

试试testData.type,而不是testData.team.type。 type 是 testData 中的属性,而不是 team 中的属性。

更新

${unitForm.testData.type} 应该在您的 JSP 中显示“棒球”。

【讨论】:

  • 我试过了,我得到 No getter method for property: testData.type of bean: "unitForm"
  • @billy:您能否更新您的帖子以包含您在 JSP 中所做的事情?
  • @billy:更新了答案。可以试试吗?
  • 您好,我试过 ${unitForm.testData.type} 得到: com.utils.TestGettingData 类没有可读属性 'type'。
  • @billy:UnitForm 中的导入语句 (import com.TestGettingData;) 建议使用不同的包。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-06
  • 2014-03-02
  • 1970-01-01
  • 2016-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多