我用SSH写的dao方法没有执行SQL语句,希望有大神帮帮忙

LOVEJA_VA 2017-11-26 10:29:47
dao方法

public User findByUser(User user) {
// TODO Auto-generated method stub
System.out.println("进入DAO111111111");
Object result= sessionFactory.getCurrentSession().
createQuery("from user where uname=? and pwd=?")
.setString(0, user.getUname())
.setString(1,user.getPwd())
.uniqueResult();
System.out.println(result);
return (User)result;

}

bean.xml

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<value>classpath:com/register/entity/*.hbm.xml</value>
</list>
</property>

</bean>
<!-- 3. 事务相关配置 -->
<!-- 3.1 事务管理器类 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* com.register.service.*.*(..))" id="pt"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/>
</aop:config>
</beans>

struts.xml

<package name="user" extends="struts-default">

<!-- 全局异常 -->
<global-exception-mappings>
<!-- result 会取找全局视图的名称 -->
<exception-mapping result="null" exception="java.lang.NullPointerException"></exception-mapping>
<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>

<action name="user_*" class="userAction" method="{1}">

<!-- 登陆失败 -->
<result name="loginfaild">/login.jsp</result>

<!-- 登陆成功 -->
<result name="index" >/register.jsp</result>

</action>
</package>


...全文
311 12 打赏 收藏 举报
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xls丶 2017-11-28
hql查的是对象,User大写
  • 打赏
  • 举报
回复
LOVEJA_VA 2017-11-28
引用 11 楼 qq_38204653 的回复:
hql查的是对象,User大写
谢了,这些细节很重要
  • 打赏
  • 举报
回复
qq_19518637 2017-11-27
楼主倒是把代码贴完呢。无语 .setString(0, user.getUname())  .setString(1,user.getPwd()) .uniqueResult();
  • 打赏
  • 举报
回复
ssy03092919 2017-11-27
action的fandByUser()方法的返回值不在struts配置文件的result中
  • 打赏
  • 举报
回复
Sunyiban 2017-11-27
你倒是把控制台的输出贴出来呀~
  • 打赏
  • 举报
回复
艺哥来了 2017-11-27
你打断点跟踪看看,看看报的啥子错
  • 打赏
  • 举报
回复
LOVEJA_VA 2017-11-27
引用 8 楼 ab1021586251 的回复:
action 配置文件看看,你的result 怎么配的
action的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:p="http://www.springframework.org/schema/p"
	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.xsd
     	 http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop.xsd
         http://www.springframework.org/schema/tx
     	 http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 将action注入到service -->
	<bean id="userAction" class="com.register.action.UserAction">
		<property name="userService" ref="userService"></property>
		
	</bean>
	
</beans>  
struts的xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

<package name="user" extends="struts-default">
	
	
		
		<!-- 全局异常 -->
		<global-exception-mappings>
			<!-- result 会取找全局视图的名称 -->
			<exception-mapping result="null" exception="java.lang.NullPointerException"></exception-mapping>
			<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
		</global-exception-mappings>
		

	
	<action name="user_*" class="userAction" method="{1}">
		
			<!-- 登陆失败 -->
			<result name="error">/login.jsp</result>
			
			<!-- 登陆成功 -->
			<result name="success" >/register.jsp</result>
		
		</action>
	</package>
 


</struts>
  • 打赏
  • 举报
回复
「已注销」 2017-11-27
action 配置文件看看,你的result 怎么配的
  • 打赏
  • 举报
回复
墨笙弘一 2017-11-27
Could not find action or result No result defined for action com.register.action.UserAction and result error SSH配置文件明显有问题啊
  • 打赏
  • 举报
回复
LOVEJA_VA 2017-11-27
引用 1 楼 u014548833 的回复:
你打断点跟踪看看,看看报的啥子错
警告: Could not find action or result No result defined for action com.register.action.UserAction and result error at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:376) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:744)
  • 打赏
  • 举报
回复
LOVEJA_VA 2017-11-27
引用 1 楼 u014548833 的回复:
你打断点跟踪看看,看看报的啥子错
警告: Could not find action or result No result defined for action com.register.action.UserAction and result error at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:376) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:744) 这个是异常
  • 打赏
  • 举报
回复
LOVEJA_VA 2017-11-27

警告: Could not find action or result
No result defined for action com.register.action.UserAction and result error
	at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:376)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
	at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:744)
这个是输出的异常错误
  • 打赏
  • 举报
回复
发帖
Java EE

6.7w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
帖子事件
创建了帖子
2017-11-26 10:29
社区公告
暂无公告