2012-11-24 4 views
0

안녕하세요, 간단한 웹 애플리케이션 양식을 작성하여 최대 절전 모드 및 서블릿을 연습하고 있습니다. 데이터를 저장하고 JSP와 서블릿을 사용하기 위해 최대 절전 모드를 사용하지 않으면 프로그램이 제대로 작동합니다. 이제 내 Hibernate 코드를 추가하여이 오류를 발생시키는 경우.Hibernate를 사용하여 서블릿에서 처리 된 데이터를 저장하는 동안 오류가 발생했습니다.

SEVERE: Servlet.service() for servlet [com.ApplicationForm.ApplicationForm] in context with path [/ApplicationForm] threw exception [Servlet execution threw an exception] with root cause 
    java.lang.ClassNotFoundException: org.hibernate.HibernateException 
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) 
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
     at com.ApplicationForm.AppFormServletHelper.doPost(AppFormServletHelper.java:54) 
     at com.ApplicationForm.ApplicationForm.doPost(ApplicationForm.java:24) 
//More errors messages here 

오류 메시지가 항상 내 최대 절전 모드 예를 클래스 AppFormServletHelper을 포함하고이 클래스를 가리 킵니다. (아래 전체 코드)

public class AppFormServletHelper extends ApplicationFormServletBase { 

    private static AppDetails applicant = new AppDetails(); 
    private static SaveApplicantData list = new SaveApplicantData(); 


    public AppFormServletHelper(HttpServlet servlet, HttpServletRequest request, HttpServletResponse response){ 
     super(servlet, request, response); 

    } 

    public void doPost() throws ServletException, IOException{ 
     int userID=0; 
     String stringUserID, firstName, lastName, address, mobile, landLine; 
     String sex, university; 


     stringUserID = request.getParameter((Integer.toString(userID))); 
     firstName = request.getParameter("firstName"); 
     lastName = request.getParameter("lastName"); 
     address = request.getParameter("address"); 
     mobile = request.getParameter("mobile"); 
     landLine = request.getParameter("landLine"); 
     sex = request.getParameter("sex"); 
     university = request.getParameter("university"); 
     //more request.getParameter lines here 

     recordApplicantDetails(userID, firstName, lastName, address, mobile, landLine, sex); 
     recordApplicantEducation(university, uniDateGrad, hsGrad, hsDateGrad, elem, elemDateGrad); 
     recordApplicantEmployment(companyN, jobRole, jobResp); 

     //Save data using hibernate 
**##Error pointing to this line** 
     **HibernateSaveData save = new HibernateSaveData(); 
     save.beginHibernateTransaction(applicant);** 

     list.addApplicantData(applicant); 
     list.setApplicantData(applicant, list); 

     request.setAttribute("AppDetails", applicant); 

     RequestDispatcher dispatch = request.getRequestDispatcher("/WEB-INF/UserDetails.jsp"); 
     dispatch.forward(request, response); 

    } 
//Implementation of recordApplicantDetails method 
//Implementation of recordApplicantEducation method 
//Implementation of recordApplicantEmployment method 

} 

이것은 ApplicationFormServletBase 클래스

@WebServlet("/appFormServlet") 
public class ApplicationForm extends HttpServlet { 

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
      throws ServletException, IOException { 

     AppFormServletHelper controllerHelper = new AppFormServletHelper(this,req, resp); 
     controllerHelper.doPost(); 
    } 

이 내 HibernateSaveData 클래스 또한 이미 내있는 hibernate.cfg.xml을 구성하고 내가 사용하고

public class HibernateSaveData { 

    private Session session; 

    public void beginHibernateTransaction(AppDetails details){ 
     session = new HibernateFactoryUtil().getSessionFactory().openSession(); 
     try{ 
      session.beginTransaction(); 
      session.save(details); 
      session.getTransaction().commit(); 

     } 
     catch (HibernateException e){ 
      if (session.getTransaction()!=null){ 
       session.getTransaction().rollback();  
      } 
      System.out.println("Hibernate exception occured: "+ e); 
     } 
     finally { 
      session.close(); 
     } 
    } 
} 

입니다 @ 서블릿에 대한 WebServlet 주석이 없으므로 xml 매핑을 구성하지 않았습니다. 모든 코드를 게시하지는 않았지만이 문제를 해결하는 데 도움이된다면 그 코드를 올려 놓을 것입니다. 아무도 이것으로 나를 도울 수 있습니까? 미리 감사드립니다.

UPDATE는

이것은 내가 내 폴더 enter image description here

을 설정하는 방법이며,이 내 hibernate.cfg.xml로

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
     "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 

    <session-factory> 

     <!-- Database connection settings --> 
     <property name="connection.driver_class">org.postgresql.Driver</property> 
     <property name="connection.url">jdbc:postgresql://localhost:5432/ApplicationForm</property> 
     <property name="connection.username">postgres</property> 
     <property name="connection.password">password</property> 

     <!-- JDBC connection pool (use the built-in) --> 
     <property name="connection.pool_size">1</property> 

     <!-- SQL dialect --> 
     <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 

     <!-- Disable the second-level cache --> 
     <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 

     <!-- Drop and re-create the database schema on startup --> 
     <property name="hbm2ddl.auto">create</property> 

     <!-- Names the annotated entity class --> 
     <mapping class="com.ApplicationForm.StoreData.AppDetails"/> 

    </session-factory> 

</hibernate-configuration> 

답변

0

프로젝트를 빌드하고 다시 컴파일하려고 당신의 수업을하고 오류가 여전히 존재하는지 확인하십시오.

+0

안녕 Murali, 나는 이미 확인하고 자바 파일을 여러 번 빌드하고 문제가 여전히 존재합니다. – dimas

0

배포 할 때 Hibernate (그리고이 경우 HibernateException)가 클래스 경로에없는 것으로 보이는 문제가 있습니다. Eclipse (예 : Eclipse)를 사용하고 있고 컴파일 오류가 발생하지 않는다고 가정하기 때문에 빌드/배포 프로세스에서 오류가 가장 많이 발생합니다.

당신은 빌드/전개 (당신은 maven을 사용하고 있는가? eclipse를 통해 전쟁을 패키징하고 그것을 서버에 업로드하고 있는가?) Hibernate 라이브러리가 위치한 곳과 클래스 패스가 그것에 대해 알고 있는가? ? etc ...) 아래쪽으로 이동합니다.

+0

안녕하세요 도와 주셔서 감사합니다. 내 게시물을 편집하고 내 폴더 및 패키지를 설정하는 방법과 내 컴퓨터의 최대 절전 모드 구성 파일을 포함 시켰습니다. 나는 Maven을 사용하지 않았고 Eclipse의 빌드 경로 옵션에 항아리 추가를 사용하여 jar 파일을 포함 시켰습니다. 나는 hibernate3.jar를 추가하고 데이터를 저장하기 위해 mysql을 사용했다. 희망은 도움이 – dimas

+0

또한 내 프로젝트 구조를 설치하는 방법, 자동으로 동적 웹 프로젝트 옵션을 사용하여 이클립스에 의해 수행됩니다. – dimas

0

WEB-INF/lib 폴더에 hibernate3.jar 파일이 있는지 확인하십시오.

관련 문제