日期:2014-05-20  浏览次数:20849 次

用工厂模式写了一个简单的显示新闻功能,可是到最后一步显示到页面上时出错了,有源码?愿望大哥帮忙看下
以下是action代码:
public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,
HttpServletRequest   request,   HttpServletResponse   response)   throws   Exception{
//   TODO   Auto-generated   method   stub
NewsDao   d=DAOFactory.getNewsDAOInstance();
ArrayList   al=d.DispNews( "select   *   from   news_table ");
//java.util.Iterator   it=al.iterator();
        request.setAttribute( "news ",   al);

return   mapping.findForward( "go ");
}

package   com.hy.factory;
import   com.hy.dao.*;
import   com.hy.daoimpl.*;
public   class   DAOFactory   {
public   static   NewsDaoImpl   getNewsDAOInstance(){
return   new   NewsDaoImpl();
}
}

package   com.hy.dao;
import   java.util.*;
public   interface   NewsDao   {
public   ArrayList   DispNews(String   sql);
}

package   com.hy.db;
import   java.sql.*;
import   java.util.*;
import   com.hy.daoimpl.NewsDaoImpl;
public   class   DbConnection   {
private   final   String   driver= "sun.jdbc.odbc.JdbcOdbcDriver ";
private   final   String   url= "jdbc:odbc:driver={Microsoft   Access   Driver   (*.mdb)};DBQ=C:\\mdb.mdb ";
private   Connection   conn=null;
public   DbConnection(){
try{
Class.forName(driver);
conn=DriverManager.getConnection(url);
}
catch(Exception   e){
e.printStackTrace();
}
}
public   Connection   getConnection(){
return   this.conn;
}
public   void   Close(){
try   {
this.conn.close();
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
}
}

package   com.hy.vo;

public   class   News   {
private   int   id;
private   String   title;
private   String   content;
public   String   getContent()   {
return   content;
}
public   void   setContent(String   content)   {
this.content   =   content;
}
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;
}

}
list   .jsp核心代码
<logic:iterate   id= "a "   name= "news ">
        <bean:write   name= "news "   property= "id "/>
        </logic:iterate>


提示说找不到id的getter方法
如果我把   property= "id "/去掉,显示了很多的内存地址
怎么回事呢


------解决方案--------------------
1、NewsDaoImpl 代码没看到还;
2、DAOFactory 要这么写:
public class DAOFactory {
public static NewsDao getNewsDAOInstance(){
return new NewsDaoImpl();
}
}