struts2提交表单时Error setting expression 'user.username' with value……的错误

项目是SSH的

Error setting expression 'user.username' with value '[Ljava.lang.String;@7787a5……

有一个持久化类Users对应数据库表Users
三个属性:id, username, password
现在有一个login.jsp中有个表单
<form action="login" method="post" >
          用户名:<input type="text" name="user.username"/>
          密码:<input type="password" name="users.password"/>
          <input type="submit" value="登录"/>
      </form>

对应的action是LoginAction类的login()方法
此类设置了private Users user;//getter setter
提交就出现前面的错误

经过反复反复反复反复……的研究实践发现错的根源……

在spring的配置文件applicationContext.xml中
为了设置事务有如下设置
<bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <tx:advice id="myAdvice" transaction-manager="myTransactionManager">
        <tx:attributes>
            <tx:method name="select*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut expression="execution(* *.*.*(..))" id="myPointCut1"/>
        <aop:advisor advice-ref="myAdvice" pointcut-ref="myPointCut1"/>

    </aop:config>
注意上面红字部分,尤其是加粗的地方,表示的是所有包下的所有返回类型所有参数配置的所有方法都会用此切面,我的程序的结构是有dao,有service调用dao,用action调用service

但是既然切面是用于一切,也就是说也作用于action,问题就出在这里,这个事务的切面不能用于action

所以把红字改成:
        <aop:pointcut expression="execution(* service.*.*(..))" id="myPointCut1"/>
        <aop:pointcut expression="execution(* dao.*.*(..))" id="myPointCut2"/>
        <aop:advisor advice-ref="myAdvice" pointcut-ref="myPointCut1"/>
        <aop:advisor advice-ref="myAdvice" pointcut-ref="myPointCut2"/
>

就是把事务作用的切面只用于service包和dao包


另外,之前还出过一个错误就是把事务切面只作用于service包,也是不行滴,必须作用于dao包
再后来发现,不用作用于service包
也就是说只作用于dao包就行了
<aop:pointcut expression="execution(* dao.*.*(..))" id="myPointCut2"/>
<aop:advisor advice-ref="myAdvice" pointcut-ref="myPointCut2"/>
有上面这两行就够了

千万别作用于action包就不会报那个错了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值