定义了bean,为什么还是出现No getter method for property name of bean 错误
1调用Action的页面
<input type= "button " value= "联系人 " name= "contact " onClick= "window.open( 'showContact.do ', '_blank ', 'scrollbars=no,status=no,width=300,height=300 ') "> <br/>
信息内容(70字内) <br> <html:textarea property= "message " cols= "40 " rows= "5 "/> <html:errors property= "message "/> <br/>
2 action
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String prompt;
getContactDAO gcDAO=new getContactDAO();
boolean mark=gcDAO.getData();
if(mark) {
prompt= "success ";
request.setAttribute( "contacts ", gcDAO.commonContactList);
}
else prompt= "fail ";
return mapping.findForward(prompt);
}
}
3 DAO
public class getContactDAO {
public getContactDAO(){
}
public
List commonContactList=new ArrayList();
public boolean getData ()
{
boolean GetRs=false;
Connection conn;
ResultSet rs;
conn=dbPool.getConnection();
try{
Statement stmt=conn.createStatement();
String sql= "select * from CommonContactList ";
rs=stmt.executeQuery(sql);
while(rs.next()){
CommonContact CContact=new CommonContact();
CContact.setName(rs.getString( "cname "));
CContact.setMobile(rs.getString( "cmobile "));
commonContactList.add(CContact);
}
GetRs=true;
}catch (SQLException e){GetRs=false;}
return GetRs;
}
}
4 bean
class CommonContact{
public String name;
public String mobile;
public CommonContact(){
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String getMobile(){
return mobile;
}
public void setMobile(String mobile){
this.mobile=mobile;
}
}
5 显示页面(报错的页面)
<%@ page language= "java " pageEncoding= "GB18030 "%>
<%@ taglib uri= "/WEB-INF/struts-bean.tld " prefix= "bean "%>
<%@ taglib uri= "/WEB-INF/struts-html.tld " prefix= "html "%>
<%@ taglib uri= "/WEB-INF/struts-logic.tld " prefix= "logic "%>
<html>
<head>
<title> JSP for DynaActionForm form </title>
</head>
<body>
<logic:present name= "contacts ">
<logic:iterate name= "contacts " id= "CContact " scope= "request ">
<bean:write name= "CContact " property= "name "/>
<bean:write name= "CContact " property= "mobile "/>
</logic:iterate>
</logic:present>
</body>
</html>
----------------------------------
报错是
The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /commonContact.jsp:14
11: <logic:present name= "contacts ">
12: <logic:iterate name= "contacts " id= "CContact " scope= "request ">
13:
14: <bean:write name= "CContact " property= "name "/>
15: <bean:write name= "CContact " property= "mobile "/>
16:
17: </logic:iterate>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.ServletException: No getter method for property name of bean CContact
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.commonContact_jsp._jspService(commonContact_jsp.java:155)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.jsp.JspException: No getter method for property name of bean CContact
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:286)
org.apache.jsp.commonContact_jsp._jspx_meth_bean_write_0(commonContact_jsp.java:172)
org.apache.jsp.commonContact_jsp._jspService(commonContact_jsp.java:107)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
已经定义了bean的方法,为什么还是提示错误,大家帮忙看看。
[解决办法]
bean类放在包下
[解决办法]
错误的意思不是找不到bean,而是bean没有getName这个方法
[解决办法]
肯定是有个对象没NEW
[解决办法]
重构一下bean
[解决办法]
这个问题是:你的bean里面的属性字段与Hibernate里面的那个映射xml文件不符合,可能是那个hbm的xml文件里面写了个属性,但是该属性在你的bean里面没有映射,结果就报这个错误了
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html