0

Hi guys, I use:

Java EE 6
Tomcat 7
Hibernate 4.1.10.Final
Mysql-connector 5.1.10
Mysql 5.6.10

It's my first web-application with Hibernate. I want to add String value to my database using Hibernate. But, getting such error from Tomcat:

type Exception report

message An exception occurred processing JSP page /doPayment.jsp at line 73

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /doPayment.jsp at line 73

70: //            hiberUtil.saveDB(read);
71:             Transaction transaction = new Transaction();
72:             transaction.setTransaction(read);
73:             Factory.getInstance().getTransactionDAO().addTransaction(transaction);
74: 
75:             List<Transaction> transactions = Factory.getInstance().getTransactionDAO().getAllTransactions();
76:             System.out.println("========Все трансакции=========");


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
    org.apache.jsp.doPayment_jsp._jspService(doPayment_jsp.java:167)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    us.test.HiberUtil.<clinit>(HiberUtil.java:26)
    us.test.TransactionDAOImpl.addTransaction(TransactionDAOImpl.java:21)
    org.apache.jsp.doPayment_jsp._jspService(doPayment_jsp.java:138)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
    us.test.HiberUtil.<clinit>(HiberUtil.java:26)
    us.test.TransactionDAOImpl.addTransaction(TransactionDAOImpl.java:21)
    org.apache.jsp.doPayment_jsp._jspService(doPayment_jsp.java:138)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

What can be a source of this error?

Here is my JSP file:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>


<%

    Token tk = new Token();
    String read;
    response.setContentType("text/html");
    String payerid = request.getParameter("PayerID");
    System.out.println(" Raw Token in DoPayment " + tk.raw_token);

    try {
        System.out.println("Sending form");
        URL url = new URL(tk.APIEndpoint);
        HttpURLConnection hConnection = (HttpURLConnection) url.openConnection();
        HttpURLConnection.setFollowRedirects(true);
        hConnection.setDoOutput(true);
        hConnection.setRequestMethod("POST");
        String token = request.getParameter("TOKEN");
        System.out.println("Token in HttpURLConnection" + token);

        PrintStream ps = new PrintStream(hConnection.getOutputStream());
        hConnection.connect();
        ps.print("USER=my_user&PWD=my_pwd&" +
                "SIGNATURE=my_signature&" +
                "VERSION=98.0&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_AMT=1.00&" +
                "PaymentActionSpecified=true&" +
                "PAYERID="+payerid+"&TOKEN=" + request.getParameter("token").replaceAll("-", "%2d") + "&" +
                "METHOD=DoExpressCheckoutPayment");
        ps.close();

        System.out.println("Form sent");
        if(HttpURLConnection.HTTP_OK == hConnection.getResponseCode()){
            System.out.println(hConnection.getContentType());
            InputStream is = hConnection.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            StringBuilder sb = new StringBuilder();
            BufferedReader br = new BufferedReader(isr);
            read = br.readLine();

            while(read != null){
                sb.append(read);
                read = br.readLine();

            }

//            Save String to Database

            Transaction transaction = new Transaction();
            transaction.setTransaction(read);
            Factory.getInstance().getTransactionDAO().addTransaction(transaction);

            List<Transaction> transactions = Factory.getInstance().getTransactionDAO().getAllTransactions();
            System.out.println("========All transactions=========");
            for(int i = 0; i < transactions.size(); ++i) {
                System.out.println("Transaction : " + transactions.get(i).getTransaction());
                System.out.println("=============================");
            }
            System.out.println(sb.toString());

            hConnection.disconnect();
            System.out.println("Connection closed.");
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


%>
</body>
</html>

Here is screenshot of my project:

enter image description here

P.s. Please don't tell me that "it's bad idea to use scriplets in JSP" :) I understand it. Trying to understand from the very beging how it works and then will improve the code.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
devger
  • 703
  • 4
  • 12
  • 26
  • Not a direct answer, but Tomcat never was and it is not Java EE, is just a Servlet Container. A real Java EE application server is JBoss (built on top of Tomcat), GlassFish, IBM WebSphere, Oracle WebLogic, etc... – Luiggi Mendoza May 21 '13 at 04:28

2 Answers2

0

Your error message does say java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration, which means the Hibernate jar files are not in your application class path, put them at the right place and your code should proceed.

Pradeep Pati
  • 5,779
  • 3
  • 29
  • 43
0

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

This means that you're missing libraries in your project. On Java Web Applications, the third party libraries must go in WEB-INF/lib folder. If this folder doesn't exists, create it manually and drop your jars there. After doing this, rebuild and redeploy your application.


Not directly related to your main question:

  • Tomcat never was and it is not Java EE, is just a Servlet Container. Some real Java EE application server are JBoss (built on top of Tomcat), GlassFish, IBM WebSphere, Oracle WebLogic. Just to let you know, there's TomEE, another real Java EE 6 application server based on Tomcat (but again, it is not Tomcat).

  • P.s. Please don't tell me that "it's bad idea to use scriplets in JSP" :) I understand it. Trying to understand from the very beging how it works and then will improve the code.

    Never use scriptlets (better explained here: How to avoid Java code in JSP files?). If you know they're evil, then don't even dare to learn about it! It's like saying I know poison is bad, but I will taste it anyway. Learn the right way and start using MVC pattern as shown in StackOverflow Servlets wiki.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332