首页上一页 1 下一页尾页 1 条记录 1/1页
《JAVAWEB开发实战宝典》第25章导入项目后,出现错误!
发表在JavaWeb图书答疑
2010-07-28
是否精华
是
否
版块置顶:
是
否
textile/src/com.lyq.util/hibernateFilter.java.
package com.lyq.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Hibenrate过滤器
* 用于初始化Session工厂及获取Session对象
* 通过ThreadLocal进行管理Session
* @author Li Yong Qiang
*/
public class HibernateFilter implements Filter{
// ThreadLocal对象
private static ThreadLocal threadLocal = new ThreadLocal();
// SessionFactory对象
private static SessionFactory factory = null;
@Override
public void destroy() {
if(!factory.isClosed()){
factory.close();
}
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
chain.doFilter(request, response);
} finally{
Session session = (Session)threadLocal.get();
if(session != null){
if(session.isOpen()){
session.close();
}
threadLocal.remove();
}
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
//初始化SessionFactory
try {
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取Session
* @return Session
*/
public static Session getSession() {
Session session = (Session)threadLocal.get();
if (session == null) {
session = factory.openSession();
threadLocal.set(session);
}
return session;
}
}
出错:1、The method destroy() of type HibernateFilter must override a superclass method。
2、The method doFilter(ServletRequest, ServletResponse, FilterChain) of type
HibernateFilter must override a superclass method。
3、The method init(FilterConfig) of type HibernateFilter must override a
superclass method。
package com.lyq.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Hibenrate过滤器
* 用于初始化Session工厂及获取Session对象
* 通过ThreadLocal进行管理Session
* @author Li Yong Qiang
*/
public class HibernateFilter implements Filter{
// ThreadLocal对象
private static ThreadLocal threadLocal = new ThreadLocal();
// SessionFactory对象
private static SessionFactory factory = null;
@Override
public void destroy() {
if(!factory.isClosed()){
factory.close();
}
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
chain.doFilter(request, response);
} finally{
Session session = (Session)threadLocal.get();
if(session != null){
if(session.isOpen()){
session.close();
}
threadLocal.remove();
}
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
//初始化SessionFactory
try {
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取Session
* @return Session
*/
public static Session getSession() {
Session session = (Session)threadLocal.get();
if (session == null) {
session = factory.openSession();
threadLocal.set(session);
}
return session;
}
}
出错:1、The method destroy() of type HibernateFilter must override a superclass method。
2、The method doFilter(ServletRequest, ServletResponse, FilterChain) of type
HibernateFilter must override a superclass method。
3、The method init(FilterConfig) of type HibernateFilter must override a
superclass method。