zoukankan      html  css  js  c++  java
  • 基于Struts+Hibernate开发过程中遇到的错误

    1.import  javax.servlet.http.HttpServletRequest 导入包出错
    导入包出错,通常是包未引入,HttpServletRequest包是浏览器通过http发出的请求, 需要将tomcat/lib 目录下的 servlet-api.jar导入。但是导入后仍然不行,重启eclipse也无法让他生效
    最后通过 project -clean来生效的

    2.JSP界面中加入了form标签后就报错

    解决办法:将tomcat/lib目录下的el-api,ecj-4.3.1jre拷贝过来了

    3.使用<c:forEach>标签,报错 Failed to load or instantiate TagLibraryValidator class

    首先在jsp界面开头添加文件
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    然后在工程目录下WEB-INF/lib目录下添加
    servlet-api.jar和standard.jar

    4.Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memo
    每次启动tomcat,没有关闭就启动,tomcat报内存泄露。解决就是关闭Eclipse,重启电脑。之后每次启动tomcat都是关闭后再启动。

    5.使用MySQL数据库。root作为连接名,连接一段时间后出现连接被拒绝的情况
    默认root用户不支持远程控制,在mysql控制台更改了root权限,仍然不起作用。最后使用了 navicat(mysql 可视化工具)创建了一个新用户,重新配置连接。

    6.数据库表a,前台向a表写入一条数据,立即查询,发现没有表a没有更新。而查看数据库服务器中的表a,数据已经更新。但在myeclipse中重新连接数据库后。再查询时,数据得到更新。
    查询方法是使用hibernate自动生成的dao
    public List findByProperty(String propertyName, Object value) {
    log.debug("finding Product instance with property: " + propertyName
    + ", value: " + value);
    try {
    String queryString = "from Product as model where model."
    + propertyName + "= ?";
    Query queryObject = getsession().createQuery(queryString);
    queryObject.setParameter(0, value);
    return queryObject.list();
    } catch (RuntimeException re) {
    log.error("find by property name failed", re);
    throw re;
    }
    }

    问题就是出现在session上。
    hibernate框架操作数据库是通过org.hibernate.Session来实现的。而Session是由org.hibernate.SessionFactory来管理的。
    Configuration conf=new Configuration().configure();//需要每次重新创建配置连接
    org.hibernate.SessionFactory sessionFactory=conf.buildSessionFactory();
    Session session=sessionFactory.openSession();

    而自动生成的dao文件中getsession()方法中只有
    public class BaseHibernateDAO implements IBaseHibernateDAO {
    public Session getSession() {
    return HibernateSessionFactory.getSession();
    }
    }





  • 相关阅读:
    18种典型算法
    幂法和反幂法
    关于Ubuntu下安装Win8和Win8下安装Ubuntu的注意事项
    静态链接库与动态链接库
    面向对象系列二(封装)
    基于ASP.NET WPF技术及MVP模式实战太平人寿客户管理项目开发(Repository模式)
    不要对终于用户谈云
    cocos2d-x 3.0 创建项目
    Android OpenGL ES 画球体
    设计模式 适配器模式 以手机充电器为例
  • 原文地址:https://www.cnblogs.com/stoneFang/p/6715328.html
Copyright © 2011-2022 走看看