提示No getter method for property 错误?想不明白!

悬赏:5 发布时间:2008-07-23 提问人:futily (初级程序员)

我写个简单的struts1.2的关于人员信息管理的东西在写好pojo、action、actionform并在xml中做好相关配置后,访问前台注册页面时总提示:
javax.servlet.jsp.JspException: No getter method for property user.owner
of bean org.apache.struts.taglib.html.BEAN
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:973)
at org.apache.struts.taglib.html.BaseFieldTag.prepareValue(BaseFieldTag.java:121)
at org.apache.struts.taglib.html.BaseFieldTag.renderInputElement(BaseFieldTag.java:102)
at org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:81)
at _jsp._register__jsp._jspService(register.jsp:36)
at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
at com.caucho.jsp.Page.pageservice(Page.java:578)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:192)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:175)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:240)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:481)
at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:685)
at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:607)
at java.lang.Thread.run(Thread.java:595)

pojo类public class Users implements Serializable {
private String name, pwd,phone,address, owner;
         setter/getter
}
我的注册页面的内容是: <%@ 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"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<html:errors />
<html:form action="/register.do" method="post">
<table border="0">
<tr>
<td>
用户名:
</td>
<td>
<html:text property="user.owner" />
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<html:password property="user.pwd" />
</td>
</tr>
<tr>
<td>
地址:
</td>
<td>
<html:text property="user.address" />
</td>
</tr>
<tr>
<td>
电话:
</td>
<td>
<html:text property="user.phone" />
</td>
</tr>
<tr>
<td>
<center>
<html:submit value="注册" />
&nbsp;
<html:reset value="重置" />
</center>
</td>
</tr>
</table>
</html:form>

我的action是 public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
RegisterForm regForm = (RegisterForm) form;
String owner = regForm.getOwner();
String pwd = regForm.getPwd();
String address = regForm.getAddress();
String phone = regForm.getPhone();

Users user = new Users();
user.setOwner(owner);
user.setPwd(pwd);
user.setAddress(address);
user.setPhone(phone);
//user.setName(null); //test this line !!!
String result=null;
boolean boo=false;
try {
UserServers us = new UserServers();
boo=us.addUser(user);

} catch (Exception e) {
e.printStackTrace();
}

if (boo == true) {
return (mapping.findForward("success"));
} else {
return (mapping.findForward("fail"));
}
}
actionform是这样写的
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
users = new Users();
}

@Override
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors = new ActionErrors();
if ((users.getOwner() == null) || (users.getOwner().length() < 6))
errors.add("owner", new ActionMessage("error.owner.required"));

if ((users.getPwd() == null) || (users.getPwd().length() < 6))
errors
.add("password", new ActionMessage(
"error.password.required"));
if ((users.getAddress() == null) || (users.getAddress().length() < 1))
errors.add("address", new ActionMessage("error.address.required"));
if ((users.getPhone() == null) || (users.getPhone().length() < 1))
errors.add("phone", new ActionMessage("error.phone.required"));
return errors;

}

public Users getUsers() {}

public void setUsers(Users users) {}

public void setOwner(String owner) { }

public String getOwner() {}

public void setPwd(String pwd) {}

public String getPwd() {}

public String getAddress() {}

public void setAddress(String address) {}

public String getPhone() {}

public void setPhone(String phone) {}
xml中的配置
<form-beans>
<form-bean name="userForm" type="org.forms.UserForm" />
<form-bean name="InsertConsumeForm"
type="org.forms.InsertConsumeForm" />

<form-bean name="registerForm" type="org.forms.RegisterForm" />
</form-beans>
<action-mappings>
<action path="/register" type="org.actions.RegisterAction"
name="registerForm" scope="request" validate="true"
input="/register.jsp">
<forward name="success" path="/functionpage.jsp"/>
<forward name="fail" path="/register.jsp"/>
</action>
</action-mappings>
问题补充:
二楼仁兄,我以前就试验过了,和那个没关系的。

采纳的答案

2008-07-24 congjl2002 (资深程序员)

怎么能没关系呢?
你Form里的是public Users getUsers() {} ,而jsp里都是<html:password property="user.pwd" />
当然是没有user这个的get方法,你改成<html:password property="users.pwd" />试试吧

提问者对于答案的评价:
见识了,还是自己存在问题。比我们公司那帮人厉害多了

其他回答

你jsp里应该users
congjl2002 (资深程序员) 2008-07-23