SSH问题请教

AngelWings 2012-07-20 02:31:24
好久没写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;
}

service部分:

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;
}
}


dao部分:

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;
}
}

问题是,加断点调试。走完这些方法就回到action里的return ERROR
...全文
346 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
AngelWings 2012-07-26
  • 打赏
  • 举报
回复
程序已经改的面目全非了,我重新做了一遍。底层完全自己写的,这次没问题了,谢谢各位。送分.....
brightyq 2012-07-20
  • 打赏
  • 举报
回复
<bean id="UsersDao" class="com.foraise.dao.impl.UsersDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

id="UsersDao" 改成小写 id="usersDao" 再试试。
sdojqy1122 2012-07-20
  • 打赏
  • 举报
回复

<!-- 配置DAO组件的父模板 -->
<bean id="daoTemplate" abstract="true">
<!-- 注入sessionFactory引用 -->
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 流水号 -->
<bean id="sequenceDao" parent="daoTemplate" class="com.cms.dao.impl.SequenceDaoImpl" />


下班了,你试下?
brightyq 2012-07-20
  • 打赏
  • 举报
回复
楼主把spring的配置文件粘出来,可能是bean没有配置对的问题。

AngelWings 2012-07-20
  • 打赏
  • 举报
回复
自己顶!

配置文件也有了,麻烦给指点下啦。谢谢!
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
applicationContext.xml 如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/redwooddb">
</property>
<property name="username" value="root"></property>
<property name="password" value="123654"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/foraise/entity/Furnituretype.hbm.xml</value>
<value>com/foraise/entity/Redwoodparameter.hbm.xml</value>
<value>com/foraise/entity/Images.hbm.xml</value>
<value>com/foraise/entity/News.hbm.xml</value>
<value>com/foraise/entity/Users.hbm.xml</value></list>
</property></bean>
<bean id="FurnituretypeDao"
class="com.foraise.dao.impl.FurnituretypeDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="RedwoodparameterDao"
class="com.foraise.dao.impl.RedwoodparameterDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="ImagesDao" class="com.foraise.dao.impl.ImagesDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="NewsDao" class="com.foraise.dao.impl.NewsDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="UsersDao" class="com.foraise.dao.impl.UsersDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="LoginService" class="com.foraise.service.impl.LoginService">
<property name="usersDao" ref="UsersDao"/>
</bean>
<bean id="LoginAction" class="com.foraise.action.LoginAction">
<property name="loginservice" ref="LoginService"/>
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<!--配置事务的传播特性-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<!-- 哪些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allServiceMethod" expression="execution(* com.foraise.service.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/>
</aop:config>

</beans>
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
我已经把所有的DAO都改成Dao了,配置文件也改了。
目测,配置文件没有报错。
xiaoman111 2012-07-20
  • 打赏
  • 举报
回复
代码没看出有什么问题,楼上说的很有可能,看看配置文件
sdojqy1122 2012-07-20
  • 打赏
  • 举报
回复
http://www.iteye.com/problems/38304
你的问题很奇怪,应该是配置问题?
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
继续顶起。

火速求支援!
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
嗯,我尽量调到下班,再不出来我就自己写底层。谢谢您!
yuxuan8701 2012-07-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]

您的意思是让我把整个自动生成的dao全部删除了自己写?
[/Quote]

能用的话,当然是可以的,但是你现在的问题就出在这,建议不要自动,手写好些,多练习下代码也是好的。
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
您的意思是让我把整个自动生成的dao全部删除了自己写?
yuxuan8701 2012-07-20
  • 打赏
  • 举报
回复
String hql = "from User u where u.uname=:uname";
Query query = getSession().createQuery(hql);
query.setParameter("uname", uname);
user = (User) query.uniqueResult();
return user;
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
value也有我从前台输入的用户名!
yuxuan8701 2012-07-20
  • 打赏
  • 举报
回复
先检查你的参数传到daoimpl没有,数据库是否有对应的记录存在,检查查询结果是否为空. 这是我的理解,希望对你有帮助,不过一般daoimpl都是自己写的吧.
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
from Users as model where model.uname= ?
qqhw123 2012-07-20
  • 打赏
  • 举报
回复
把你的queryString打印出来看看。
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
自己顶起,请求支援。我已经调的没头绪了.....
AngelWings 2012-07-20
  • 打赏
  • 举报
回复
daoimpl是myeclipse8.6自己生成的。
加载更多回复(2)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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