日期:2014-05-18  浏览次数:20671 次

如何实现struts action在查询数据库后,把结果返回给jsp页面?
下面是一个aciton,用来读取相应文章标题后,获取文章内容。现在的问题是怎么样使查询到的文章内容显示在跳转的jsp页面。谢谢各位,请指点

public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,
HttpServletRequest   request,   HttpServletResponse   response)   {
//   TODO   Auto-generated   method   stub
ISOtogb2312   gb   =   new   ISOtogb2312();
String   title   =   gb.convert(request.getParameter( "title "));

Session   session=HibernateSessionFactory.getSession();
Transaction   tx=session.beginTransaction();
try
{
String   hql   =   "select   article.body   from   Article   as   article   where   article.title= ' "+title+ " ' ";
Query   query   =   session.createQuery(hql);
        Iterator   it   =   query.iterate();
        tx.commit();
        while(it.hasNext())
        {
        Article   article   =   (Article)it.next();
        String   body   =   article.getBody();
        System.out.println(body);
        }
}catch(Exception   e){System.out.println(e.getMessage());}
return(mapping.findForward( "showarticle "));
}



------解决方案--------------------
用一个ArrayList 把所有的body存进去
然后把这个ArrayList放进request

然后再在showarticle 页面用标签 或者代码显示