在做新闻查询时:
报了一个错javax.servlet.jsp.JspException: No getter method for property: "id" of bean: "news"
报错处的代码如下:
<logic:iterate id="news" name="newslist">
<tr>
<td><bean:write name="news" property="id" /></td>
<td><bean:write name="news" property="title" /></td>
<td><bean:write name="news" property="content" /></td>
<td><bean:write name="news" property="createdate" /></td>
<logic:notEmpty name="user" property="username">
<td ><input type="button" value="修改" onclick="Update(this)" />
<input type="button" value="删除" onclick="dele(this)" /></td>
</logic:notEmpty>
</tr>
</logic:iterate>
但是如果数据库里面没有记录的话,没报错。。
News类的代码如下:
public class News {
private int id;
private String title;
private String content;
private Date createdate;
private String starttime;
private String endtime; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public Date getCreatedate() {
return createdate;
} public void setCreatedate(Date createdate) {
this.createdate = createdate;
} public String getStarttime() {
return starttime;
} public void setStarttime(String starttime) {
this.starttime = starttime;
} public String getEndtime() {
return endtime;
} public void setEndtime(String endtime) {
this.endtime = endtime;
}
}查询有四个文本框分别是:title,content,starttime,endtime。
HQL没问题,因为我把list.size长度打印出来,结果是正确的。。
Action里面的方法是这样的:
public ActionForward select(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
NewsForm newsform=(NewsForm) form;
News news = new News();
BeanUtils.copyProperties(news, newsform);
List list=newsService.select(news);
request.setAttribute("newslist",list);
return mapping.findForward("selectsuccess");
}
其中NewsForm是form层用来与struts交互,News与hibernate交互
public class NewsForm extends ActionForm {
private int id;
private String title;
private String content;
private Date createdate;
private String starttime;
private String endtime; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public Date getCreatedate() {
return createdate;
} public void setCreatedate(Date createdate) {
this.createdate = createdate;
} public String getStarttime() {
return starttime;
} public void setStarttime(String starttime) {
this.starttime = starttime;
} public String getEndtime() {
return endtime;
} public void setEndtime(String endtime) {
this.endtime = endtime;
}
}
struts的配置文件都对的。。配置如下:
<form-bean name="news" type="com.zp.form.NewsForm" />
<action path="/NewsAction"
type="org.springframework.web.struts.DelegatingActionProxy"
name="news"
scope="session"
input="login.jsp"
parameter="flag"
>
<forward name="selectsuccess" path="/selectnews.jsp"></forward>
</action>谢谢了!!
报了一个错javax.servlet.jsp.JspException: No getter method for property: "id" of bean: "news"
报错处的代码如下:
<logic:iterate id="news" name="newslist">
<tr>
<td><bean:write name="news" property="id" /></td>
<td><bean:write name="news" property="title" /></td>
<td><bean:write name="news" property="content" /></td>
<td><bean:write name="news" property="createdate" /></td>
<logic:notEmpty name="user" property="username">
<td ><input type="button" value="修改" onclick="Update(this)" />
<input type="button" value="删除" onclick="dele(this)" /></td>
</logic:notEmpty>
</tr>
</logic:iterate>
但是如果数据库里面没有记录的话,没报错。。
News类的代码如下:
public class News {
private int id;
private String title;
private String content;
private Date createdate;
private String starttime;
private String endtime; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public Date getCreatedate() {
return createdate;
} public void setCreatedate(Date createdate) {
this.createdate = createdate;
} public String getStarttime() {
return starttime;
} public void setStarttime(String starttime) {
this.starttime = starttime;
} public String getEndtime() {
return endtime;
} public void setEndtime(String endtime) {
this.endtime = endtime;
}
}查询有四个文本框分别是:title,content,starttime,endtime。
HQL没问题,因为我把list.size长度打印出来,结果是正确的。。
Action里面的方法是这样的:
public ActionForward select(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
NewsForm newsform=(NewsForm) form;
News news = new News();
BeanUtils.copyProperties(news, newsform);
List list=newsService.select(news);
request.setAttribute("newslist",list);
return mapping.findForward("selectsuccess");
}
其中NewsForm是form层用来与struts交互,News与hibernate交互
public class NewsForm extends ActionForm {
private int id;
private String title;
private String content;
private Date createdate;
private String starttime;
private String endtime; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public Date getCreatedate() {
return createdate;
} public void setCreatedate(Date createdate) {
this.createdate = createdate;
} public String getStarttime() {
return starttime;
} public void setStarttime(String starttime) {
this.starttime = starttime;
} public String getEndtime() {
return endtime;
} public void setEndtime(String endtime) {
this.endtime = endtime;
}
}
struts的配置文件都对的。。配置如下:
<form-bean name="news" type="com.zp.form.NewsForm" />
<action path="/NewsAction"
type="org.springframework.web.struts.DelegatingActionProxy"
name="news"
scope="session"
input="login.jsp"
parameter="flag"
>
<forward name="selectsuccess" path="/selectnews.jsp"></forward>
</action>谢谢了!!
或者你试一下C标签
<hibernate-mapping>
<class name="com.zp.model.News" table="NEWS" schema="SCOTT">
<id name="id" type="integer">
<column name="ID" precision="3" scale="0" />
<generator class="sequence">
<param name="sequence">sid</param>
</generator>
</id>
<property name="title" type="java.lang.String">
<column name="TITLE" length="25" />
</property>
<property name="content" type="java.lang.String">
<column name="CONTENT" length="500" />
</property>
<property name="createdate" type="java.util.Date">
<column name="CREATEDATE" length="7" />
</property>
<property name="starttime" type="java.lang.String">
<column name="STARTTIME" length="50" />
</property>
<property name="endtime" type="java.lang.String">
<column name="ENDTIME" length="50" />
</property>
</class>
</hibernate-mapping>
打印下拟的list里面是否是news对象
No getter method for property: "id" of bean: "news"
这个是问题的根源。如果没有数据的话,list=empty,当然不会进入循环,也不会去call你的getId方法。
你试试把那个属性改成Integer,然后把set和get方法删掉,重新用eclipse生成set和get方法。
另外,你也不要把注意力全都放在id上,因为id是你的logic中的第一个取的元素,第一个元素报错,jsp就停止解析了。也许你调换一下顺序,就变成其他的某个属性的get方法找不到了。如果是这样的话,也就是说,问题不在id上,而是在这个bean上。
就是bean注入没有写getter方法javax.servlet.jsp.JspException: No getter method for property: "id" of bean: "news" 你的Action类没有写注入bean,就是没有写getter 方法。你检查看看
按照你的意思,我第一次登录是应该报错的。。
好像是这里出错吧?select方法确定返回就是News这种类型吗?有没有可能是Object呢?如果是后者当然就报没有getter && setter方法啦。
是因为sql在做怪
我用hql是News那个类型,但是用sql来查询不是News那个类型,真郁闷啊!