继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

SSH员工管理系统框架整合的源代码(大家帮我查一下哪里有问题,总是报错)

玄鉴
关注TA
已关注
手记 96
粉丝 237
获赞 4217

applicationContext.xml 文件


    <!-- 引入外部属性文件 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!--配置连接池  -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>

<!--配置hibernate相关属性  -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--注入连接池  -->
<property name="dataSource" ref="dataSource"></property>
<!-- 配置hibernate的属性 -->

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect" > org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect</prop>
 -->
 <prop key="hibernate.show_sql">true</prop>
 <prop key="hibernate.format_sql">true</prop>
 <prop key="hibernate.hbm2ddl.auto">update</prop>

 </props>

</property>
<!-- <property name="mappingLocations" value="classPath:cn/mooc/daoMain/*.hbml.xml">

</property> -->

<property name="mappingResources">
<list>
<value>cn/mooc/daoMain/Product.hbml.xml</value>
</list>
</property>
</bean>
    <!-- 配置action类 -->

    <bean id="ProductAction" class="cn.mooc.action.ProductAction" scope="prototype">
    <property name="ProductService" ref="ProductService"></property>

    </bean>
    <!-- 配置业务层的类 -->
<bean id="ProductService" class="cn.mooc.service.ProductService">
<property name="ProductDao" ref="ProductDao"></property>

</bean>
<!-- 配置dao层的类 -->
<bean id="ProductDao" class="cn.mooc.dao.ProductDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!--配置事物管理 工具类  -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>

</bean>
<!-- 开启注解事物 -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="get*" read-only="true"/>
    <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
</tx:advice>

</beans>

struts2文件

<?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="ssh" extends="struts-default" namespace="/"  >
   <action name="product_save" class="ProductAction" method="save">

   </action>

   </package>
</struts>
//商品action
public class ProductAction extends ActionSupport implements
        ModelDriven<Product> {
    // 模型驱动的类
    private Product product =new Product();
    public Product getModel() {
        // TODO Auto-generated method stub
        return product;
    }
    // strtus和spring 整合过程按名称自动注入的业务层类
    private ProductService productService;
    public ProductService getProductService() {
        return productService;
    }
    public void setProductService(ProductService productService) {
        this.productService = productService;
    }
    public String save() {
        System.out.println("action中的save方法执行了");
        productService.save(product);
        return NONE;
    }
}
//商品dao层
public class ProductDao extends HibernateDaoSupport {

    public void save(Product product) {
        System.out.println("dao中的save方法");
        HibernateTemplate hibernTemplate=   this.getHibernateTemplate();

        hibernTemplate.save(product);
    }

}

映射文件:

<<hibernate-mapping>
<class name="cn.mooc.daoMain.Product" table="Product">
<id name="pid" column="pid">
<generator class="native"/>
</id>
<property name="pname" column="pname" length="20"/>
<property name="price" column="price"/>
</class>

</hibernate-mapping>
//商品业务层注入dao的类
@Transactional
public class ProductService {

    // 业务层注入dao的类
    private ProductDao productDao;

    public ProductDao getProductDao() {
        return productDao;
    }

    public void setProductDao(ProductDao productDao) {
        this.productDao = productDao;
    }

    public void save(Product product) {
        System.out.println("service中的save方法");
        productDao.save(product);
    }

}

jsp文件:

 <body>

<h1>保存商品</h1>

<s:form action="product_save" method="post" theme="simple">

<table>
<tr>
<td>商品名称</td>
<td><s:textfield name="pname"/></td>

</tr>
<td>商品价格</td>
<td><s:textfield name="price"/></td>

</tr>

</tr>

<td colspan="2"><input type="submit" value="添加"/></td>

</tr>

</table>

</s:form>

  </body>

报错提示:

六个报错,求救

第一1.7jdk

信息: validateJarFile(E:\Tomcat7\webapps\ssh\WEB-INF\lib\javax.servlet-3.1.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
第二:”那个文档

ERROR - Error parsing XML: XML InputStream(5) 文档中根元素前面的标记必须格式正确。
Error on line 5 of document : 文档中根元素前面的标记必须格式正确。 Nested exception: 文档中根元素前面的标记必须格式正确。
第三,好多人都出了这个问题。但是没有能解决的。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
第四:
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream

第五

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
第六:

严重: Error listenerStart

打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP