您的位置:首页 > 编程语言 > Java开发

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

2016-01-13 16:38 435 查看
项目是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包就不会报那个错了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: