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包就不会报那个错了
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包就不会报那个错了
相关文章推荐
- 使用proguard混淆java web项目代码
- java与mysql数据类型对应表
- spring mvc web应用启动时就执行特定处理(线程启动)
- MyEclipse + Maven开发Web工程的详细配置过程
- 用java解析在OpenStreetMap上下载的地图数据
- 7天学会spring cloud教程
- Java中系统属性Properties介绍 System.getProperty()参数大全
- java加密解密研究-MAC算法家族
- E326:判断一个数是3的幂
- Spring Security介绍
- struts2 iterator标签status属性
- ecilpse升级jdk1.8遇到若干问题
- 进制转换补0工具类
- Java IO 技术之基本流类 ~~~~~~~~ (图+讲解+代码) 好好看 有好处
- 在eclipse上跑hadoop的helloworld
- java代码获得类属于哪个包
- 第二章 SpringMVC之 DispatcherServlet解析
- springmvc 环境搭建
- spring 事务配置方法
- Java异常解读