SSH问题请教
好久没写SSH了,最近写了一个登录发现好多问题,请大侠赐教!
action部分:
public String login() throws Exception{ System.out.print(users.getUname()); System.out.print(users.getUpwd()); try { Users loginUser=loginservice.login(users.getUname(),users.getUpwd()); if(loginUser!=null){ ActionContext context=ActionContext.getContext(); context.getSession().put("LOGINUSER", loginUser); return SUCCESS; } } catch (Exception e) { log.error("登录查询失败", e); return ERROR; } return INPUT; }
public Users login(String uname,String upass){ List list=usersDAO.findByUname(uname); if(list==null ||list.size()==0){ return null; } Users users=(Users)usersDAO.findByUname(uname).get(0); if(users==null){ return null; } if(uname.equals(users.getUname())&&upass.equals(users.getUpwd())){ return users; }else{ return null; } }
public List findByUname(Object uname) { return findByProperty(UNAME, uname); }
public List findByProperty(String propertyName, Object value) { log.debug("finding Users instance with property: " + propertyName + ", value: " + value); try { String queryString = "from Users as model where model." + propertyName + "= ?"; return getHibernateTemplate().find(queryString, value); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } }
<!-- 配置DAO组件的父模板 --> <bean id="daoTemplate" abstract="true"> <!-- 注入sessionFactory引用 --> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 流水号 --> <bean id="sequenceDao" parent="daoTemplate" class="com.cms.dao.impl.SequenceDaoImpl" />
[解决办法]
<bean id="UsersDao" class="com.foraise.dao.impl.UsersDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
id="UsersDao" 改成小写 id="usersDao" 再试试。