안녕하세요, 간단한 웹 애플리케이션 양식을 작성하여 최대 절전 모드 및 서블릿을 연습하고 있습니다. 데이터를 저장하고 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는
이것은 내가 내 폴더
을 설정하는 방법이며,이 내 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>
안녕 Murali, 나는 이미 확인하고 자바 파일을 여러 번 빌드하고 문제가 여전히 존재합니다. – dimas