在做新闻查询时:
报了一个错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>谢谢了!!

解决方案 »

  1.   

    javax.servlet.jsp.JspException 这个是说你的jsp页面出错,我前段时间也遇到过。可能是你的logic标签用法出错,我把logic标签改了一下,它就好了。
    或者你试一下C标签
      

  2.   

    我的news.hbm.xml配置是这样的:
    <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>
      

  3.   

    问题在于我单测struts就可以,ssh整合在一起就报错,我不知道问题在哪里,测了一下午了,真是郁闷了
      

  4.   

    感觉struts1的标签并不好用,还是用C标签吧。个人建议
      

  5.   

    Sorry,不懂,爱莫能助了,帮你顶下了。。
      

  6.   

    List list=newsService.select(news); 
    打印下拟的list里面是否是news对象
      

  7.   

    javax.servlet.jsp.JspException: No getter method for property: "id" of bean: "news" 你的Action类没有写注入bean,就是没有写getter 方法。你检查看看
      

  8.   

    news和new   大小写   方法什么的     检查一下     我以前也遇到过这问题 
      

  9.   

    很明显:
    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上。
      

  10.   


    就是bean注入没有写getter方法javax.servlet.jsp.JspException: No getter method for property: "id" of bean: "news" 你的Action类没有写注入bean,就是没有写getter 方法。你检查看看
      

  11.   

    我第一次登录时,就是用类似的方法来读新闻的,可以成功,唯一的区别的是在那个方法里面没有News那个类,直接把list丢过去的
    按照你的意思,我第一次登录是应该报错的。。
      

  12.   

    我把id去掉,报第二个错。。就是title没有get方法,我明天再试试吧。。我百思不得其解。。第一次读取新闻没 new出新闻来,只是传了一个list过去,这样可以的,现在只是new出一个新闻而已,因为我要利用这个新闻来进行多条件的查询,居然不行了。。
      

  13.   

    List list=newsService.select(news); 
    好像是这里出错吧?select方法确定返回就是News这种类型吗?有没有可能是Object呢?如果是后者当然就报没有getter && setter方法啦。
      

  14.   

    谢谢大家,问题已经解决了。。
    是因为sql在做怪
    我用hql是News那个类型,但是用sql来查询不是News那个类型,真郁闷啊!