SSH框架JSP 无法显示数据库数据的问题

shyhappyaa 2009-03-26 09:47:34
最近在学习struts+spring+hibernate,在MyEclipse中自动创建持久化类Address,在Action中用DAO调用list方法显示数据库信息,
现在可以成功调用list方法但Hibernate给我返回的username是null(MySQL中有数据),所以jsp页面中显示不出数据库信息,请问这是什么原因造成的?

这是DAO中的list方法

 public class AddressDAO extends HibernateDaoSupport implements IAddressDAO {
public List findAllByUsername(final String username) {
return (List) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
List result = session.createCriteria(Address.class).add(
Restrictions.eq("username", username)).list();
//System.out.println("111");
return result;
}
});
}
…………


这是Action 中调用list

public class AddressAction extends DispatchAction {
protected AddressDAO addressDAO;
Logger log = Logger.getLogger(this.getClass());

public AddressDAO getAddressDAO() {
return addressDAO;
}

public void setAddressDAO(AddressDAO addressDAO) {
this.addressDAO = addressDAO;
}

public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String username = (String) request.getSession().getAttribute(
Constants.USERNAME_KEY);

List list = addressDAO.findAllByUsername(username);

request.setAttribute("addressList", list);

ActionForward forward = mapping.findForward(Constants.LIST_KEY);

return (forward);
}

返回信息就是这样
null
Hibernate: select this_.ID as ID0_0_, this_.username as username0_0_, this_.name as name0_0_, this_.sex as sex0_0_, this_.mobile as mobile0_0_, this_.email as email0_0_, this_.qq as qq0_0_, this_.company as company0_0_, this_.address as address0_0_, this_.postcode as postcode0_0_ from address.address this_ where this_.username=?
...全文
228 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ch370335226 2009-03-26
  • 打赏
  • 举报
回复
String username = (String) request.getSession().getAttribute(
Constants.USERNAME_KEY);



session 中有没有值???
Study_Work_2009 2009-03-26
  • 打赏
  • 举报
回复
应该是username的注入问题吧
lvkai0452 2009-03-26
  • 打赏
  • 举报
回复
where this_.username=?这个条件查询没有值吧

81,076

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧