2 zyhlearnjava zyhlearnjava 于 2017.01.16 11:17 提问

ssh整合问题,怎么办,求指导

tomcat启动正常,showsql 也打开了,用jsp输出数据做测试,数据是从数据库查询的,现在页面没数据输出,控制台也没有sql语句出来

13个回答

u013829202
u013829202   Rxr 2017.01.16 13:01

没报错吗? 你debug有数据吗?

u013829202
u013829202 你的hbm.xml。class的name要用java的全限定名。 <class name="这个地方用全限定名" table="t_dept">
一年多之前 回复
u011806486
u011806486 回复宏飞英翔: 对
一年多之前 回复
u011806486
u011806486 测试看看
一年多之前 回复
zyhlearnjava
zyhlearnjava 没报错,我是自学的,web项目不会debug
一年多之前 回复
static_coder
static_coder   2017.01.16 14:33

看项目有没有部署到服务器上?

zyhlearnjava
zyhlearnjava 部署上去了,写了测试类,可以查询,就是jsp没有输出查询结果,而且控制台也没sql语句出来
一年多之前 回复
zyhlearnjava
zyhlearnjava   2017.01.17 01:05

我在浏览器直接调action,org.hibernate.MappingException: Unknown entity: 出现这个错误

zyhlearnjava
zyhlearnjava 回复智_永无止境: 引入了啊,我看看可不可以把代码发上来
一年多之前 回复
static_coder
static_coder 那你看看这个实体在什么地方有么有引入?在配置文件中看看映射又不是没有引入?
一年多之前 回复
qq_24972061
qq_24972061   2017.01.17 08:27

用debug进行调试呗。。。。

zyhlearnjava
zyhlearnjava 好的,谢谢,我还不会用debug,我是自学的,我去找找资料
一年多之前 回复
zyhlearnjava
zyhlearnjava   2017.01.17 14:18

图片说明这是结构

zyhlearnjava
zyhlearnjava   2017.01.17 15:01

我用junit测试,可以查询输出到控制台。我把别人的源代码拷过来也是这个样子,我用浏览器直接调action,浏览器报错,访问页面又没数据图片说明

zyhlearnjava
zyhlearnjava   2017.01.17 15:03

dept.hbm.xml

 <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<!-- 

  This mapping demonstrates content-based discrimination for the
  table-per-hierarchy mapping strategy, using a formula
  discriminator.

-->

<hibernate-mapping  package="entity">

    <class name="Dept" table="t_dept">
        <!-- 主键,映射 -->
        <id name="id" column="deptId">
            <generator class="native"/>
        </id>
        <!-- 非主键,映射 -->
        <property name="name" column="deptName"></property>

    </class>


</hibernate-mapping>

employee.hbm.xml

 <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<!-- 

  This mapping demonstrates content-based discrimination for the
  table-per-hierarchy mapping strategy, using a formula
  discriminator.

-->
<hibernate-mapping  package="entity">   
    <class name="Employee" table="t_employee">
        <!-- 主键,映射 -->
        <id name="id" column="empId">
            <generator class="native"/>
        </id>
        <!-- 非主键,映射 -->
        <property name="empName" ></property>
        <property name="salary" ></property>
        <!-- 多对一 -->
        <many-to-one name="dept" column="dept_id" class="Dept"></many-to-one>
    </class>
</hibernate-mapping>
zyhlearnjava
zyhlearnjava   2017.01.17 15:06

bean-base.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">


    <!-- 所有配置的公共部门 -->

    <!-- 1) 连接池实例 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mydb"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
        <property name="initialPoolSize" value="3"></property>
        <property name="maxPoolSize" value="6"></property>
    </bean>

    <!-- 2) SessionFactory实例创建 -->
    <!-- 所有的配置都由spring维护(项目中不需要hibernate.cfg.xml啦) -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!-- a. 连接池 -->

        <property name="dataSource" ref="dataSource"></property>

        <!-- b. hibernate常用配置: 方言、显示sql、自动建表等 -->
        <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>entity/*.hbm.xml</value>
            </list>
        </property>

    </bean>

    <!-- 3) 事务配置 -->
    <!-- # 事务管理器 -->
    <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配置 -->
    <aop:config>
        <aop:pointcut expression="execution(* service.*.*(..))" id="pt"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/>
    </aop:config>

</beans>     

bean-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">

    <bean id="employeeAction" class="action.EmployeeAction" scope="prototype">
        <property name="employeeService" ref="employeeService"></property>
    </bean>

</beans>     










bean-service.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">


<bean id="employeeService" class="service.EmployeeService">
    <property name="employeeDao" ref="employeeDao"></property>
</bean>

</beans>     










bean-dao.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">


    <bean id="employeeDao" class="dao.EmployeeDao">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

</beans>     










zyhlearnjava
zyhlearnjava   2017.01.17 15:11

struts.xml

 <?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
          "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
   <package name="action" extends="struts-default" >
        <action name="show" class="action.EmployeeAction" method="execute">
            <result name="success">/index.jsp</result>
        </action>    
    </package>   
</struts>

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ssh</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!-- Struts2配置 -->
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- spring配置 -->
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/bean*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>
zyhlearnjava
zyhlearnjava   2017.01.17 15:14

employeeAction.java

 package action;





import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import entity.Employee;
import service.EmployeeService;
import javax.persistence.Entity;



public class EmployeeAction extends ActionSupport{
    private EmployeeService employeeService;    
    public void setEmployeeService(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }
    @Override
    public String execute() {
        // TODO Auto-generated method stub
        int empId=2;
        Employee emp = employeeService.findById(empId);
        Map<String, Object> request= (Map<String, Object>) ActionContext.getContext().get("request");
        request.put("emp", emp);

        return "success";
    }

    //这是做测试用的,没有配置进配置文件,与主体无关
    public Employee find(int id) {
        // TODO Auto-generated method stub

        Employee emp = employeeService.findById(id);
        return emp;
    }
}

employeeService.java

 package service;

import java.io.Serializable;

import org.hibernate.SessionFactory;

import dao.EmployeeDao;
import entity.Dept;
import entity.Employee;

public class EmployeeService {
    private EmployeeDao employeeDao;
    public void setEmployeeDao(EmployeeDao employeeDao) {
        this.employeeDao = employeeDao;
    }
    public Employee findById(Serializable id) {
        Employee emp = employeeDao.findById(id);
        return emp;
    }
}

employeeDao.java

 package dao;

import java.io.Serializable;

import org.hibernate.SessionFactory;

import entity.Dept;
import entity.Employee;

public class EmployeeDao {
    private SessionFactory sessionFactory;  
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    public Employee findById(Serializable id) {
//      return (Employee) sessionFactory.openSession().get(Employee.class, id);
        return (Employee)sessionFactory.getCurrentSession().get(Employee.class, id);
    }
}
共13条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
整合SSH框架及常见问题解决
如何快速的搭建javaweb应用框架是每一个java程序员必做的事情,通过自己的学习也是初步的可以搭建好ssh框架。下面是详细搭建过程及一些途中遇到的问题和解决方案,博主使用的是myeclipse,方便框架导入 - 新建工程 - 导入spring框架 - 导入Struts框架 - 导入hibernate框架 - 整合配置文件 - spring配置常用bean - 常见问题spring
关于SSH整合时遇到的一些问题
小弟最近自学关于SSH版的WEB项目,这几天整合SSH时也报了很多错误。所以特此写下一些遇到的错误以供大家和自己以后借鉴 1.报获取bean空指针 那么很可能你web.xml没有初始化spring.连初始化都没有,那么肯定是空指针。 2.报所在类找不着时,而你确实导进去了,看你是否是先导入WEB-INF目录下的LIB文件夹下。 3.报JSP页面错误时,很可能是版本不支持。在指令改为即可。
整合ssh的时候出现空指针java.lang.NullPointerException
HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.NullPointerExcepti
ssh框架整合的jar包冲突问题
Apache Tomcat/7.0.59 - Error report<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-colo
ssh整合出现的一些问题的解决
Ignoring namespace handler [org.springframework.scripting.config.LangNamespaceHandler]: handler class not found Spring Hibernate在AOP方面的配置冲突 Spring2.0 Hibernate3.1.x/Hibernate3.2 在使用Spring的AOP编程时,会用到这几个lib:
struts2整合jfreechart的经验之谈(痛的教训)
一个java web项目中需要用到图表显示,于是我选择了jfreechart(正常人都会想到..)鉴于这次给我的教训比较大,花的时间也比较多,于是将struts2整合jfreechart的方法写下来,纪念这几天花去的时间和精力。 第一,jfreechart的使用,不多说网上很多资料..          需要下载的包有 struts2-core-2.1.6.jar freemarker-
SSH三大框架整合出现包冲突,要删除的jar包
首先删两个架包: 1.struts2的:Window-->Preferences-->myeclipse-->project capabilities-->struts2-->antlr-2.7.2.jar 2.hibernate的:Window-->Preferences-->myeclipse-->project capabilities-->Hibernate-->Hibernate3.
SSH整合时出现的问题
今天调试程序,很简单的demo,可是出现了exception Invalid action class configuration that references an unknown class namedjava.lang.RuntimeException: Invalid action class configuration that references an unknown class
ssh2框架整合详细版(使用较新jar包)
ssh2框架整合+Maven+详细配置、多种方式介绍,中间碰到问题与注意点,部分已有指出。关于Eclipse中使用Maven详见http://blog.csdn.net/it_faquir/article/details/54562242步骤一导入必备junit、javax.servlet相关jar包,maven配置如下:<dependency> <groupId>junit</groupI
SSH框架整合常见异常错误
1.java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor 缺少asm-3.3.jar 2.java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor 缺少asm-commons-3.3.jar 3.java.lang.Cl