最近学Struts 不久 就遇到了 页面首次加载 需要读取数据库里面的数据 在网上找了半天 也没有一个我用的着的 突然想到了 bean 里面的一个reset 方法 在这个方法里面写上要从数据库里面读取的数据 问题解决了;现在把这个方法的代码写上来:
public void reset(ActionMapping mapping, HttpServletRequest request) {
try {
request.setCharacterEncoding("gbk");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
INationInfoDao nationDao = new NationInfoDao();
ICultureInfoDao cultureDao = new CultureInfoDao();
IRelationInfoDao relationDao = new RelationInfoDao();
IMoveStateInfoDao moveDao = new MoveStateInfoDao();
List<NationInfo> listNation = nationDao.selectNationInfo();
List<CultureInfo> listCulture = cultureDao.selectCultureInfo();
List<RelationInfo> listRelation = relationDao.selectRelationInfo();
List<MoveStateInfo> listMove = moveDao.selectMoveStateInfo();
request.setAttribute("listNation", listNation);
request.setAttribute("listCulture", listCulture);
request.setAttribute("listRelation", listRelation);
request.setAttribute("listMove", listMove);
request.removeAttribute("personInfoForm");
}