0

早上好,我不知道如何解决该异常,我在 Eclipse 下使用 ApcheTomcat 7,每次运行我的 servlet 时都会抛出该异常,为了更清楚,这里是我的 servlet:

package servlets;

import java.util.*;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 import dao.*;

@WebServlet("/AdminServlt")
public class AdminServlt extends HttpServlet {
private static final long serialVersionUID = 1L;
CarHome carDao;

public void init(ServletConfig config) throws ServletException{
    carDao = new CarHome();
    }

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    populateAdminView(request, response);
}

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
}

  public void populateAdminView(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
    ArrayList productsList = (ArrayList) carDao.extractAdminAttributes();
    HttpSession session = request.getSession(true);
    session.setAttribute("product_list",productsList);
    RequestDispatcher rd = request.getRequestDispatcher("Admin.jsp");
    rd.forward(request, response);
}

}

这是CarHome.java

package dao;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;  
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.*;
import entity.*;

    public class CarHome {

private static final Log log = LogFactory.getLog(CarHome.class);

private final SessionFactory sessionFactory = getSessionFactory();


public List extractAdminAttributes() {
    log.debug("Extracting car attributes for administrator view");
    try {
        ArrayList results = (ArrayList) sessionFactory
                .getCurrentSession()
                .createCriteria("pojo.Car")
                .setProjection(
                        Projections.projectionList()
                                .add(Projections.property("carDesc"))
                                .add(Projections.property("price"))
                                .add(Projections.property("quantity")));

        return results;
    } catch (RuntimeException re) {
        log.error("find by admin view failed");
        throw re;
    }
  }
  }

这是异常的堆栈跟踪

java.lang.ClassNotFoundException: org.hibernate.criterion.Projection
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
servlets.AdminServlt.init(AdminServlt.java:31)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
4

2 回答 2

2

我已经解决了我的问题,这很简单,主要原因是当我把 hibernate.cor.jar 文件放在应用程序的 web 内容下的 lib 文件夹中时,它工作正常

于 2013-02-28T10:50:53.573 回答
0

我遇到了同样的问题,但在我的情况下,我使用 eclipse 在顶部重新订购了 hibernate-cor.jar

选择项目-->右键单击-->构建路径-->订单选项卡-->选择hibernate-cor.jar点击顶部

于 2016-06-25T14:28:44.463 回答