java方法无法在jsp文件中运行

时间:2014-03-16 20:16:54

标签: java hibernate jsp

我有问题。 我已经在eclipse hibernate中配置了mysql中的数据库。 我创建了一个文件java,如果我尝试将一些数据保存到数据库中就可以完美地工作。

问题是,如果我创建一个jsp文件,并尝试调用相同的方法它不起作用,我想它不会与hibernate连接。

public class CreateData {
    public int age;

    public static void main(String[] args) throws Exception {

            SessionFactory sessFact = HibernateUtil.getSessionFactory();
            Session session = sessFact.getCurrentSession();
            org.hibernate.Transaction tr = session.beginTransaction();
            Employee emp = new Employee();
            emp.setEmpName("Deepak Kumar");
            emp.setEmpMobileNos("000000");
            emp.setEmpAddress("Delhi - India");
            session.save(emp);
            tr.commit();
            System.out.println("Successfully inserted");
            sessFact.close();
    }




    public void insert() throws Exception {

            SessionFactory sessFact = HibernateUtil.getSessionFactory();
            Session session = sessFact.getCurrentSession();
            org.hibernate.Transaction tr = session.beginTransaction();
            Employee emp = new Employee();
            emp.setEmpName("Deepak Kumar");
            emp.setEmpMobileNos("000000");
            emp.setEmpAddress("Delhi - India");
            session.save(emp);
            tr.commit();
            System.out.println("Successfully inserted");
            sessFact.close();
    }
           public int getAge(){return this.age;}

}

因此,如果运行此类java的主要内容,一切正常。

但我不能在这个jsp文件中运行insert()方法(显然有些东西是主要的) JSP FILE示例:    jsp:useBean id =“user”class =“javabean.CreateData”scope =“session”

<%user.getAge();%> //这个工作

<%user.insert();%> //这不起作用


当我运行jsp时给我一个错误

堆栈跟踪:     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) javax.servlet.ServletException:java.lang.NoClassDefFoundError:org / hibernate / HibernateException     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)     org.apache.jsp.savesclient_jsp._jspService(savesclient_jsp.java:121)     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)         java.lang.NoClassDefFoundError:org / hibernate / HibernateException     javabean.insertClient.inserisci2(insertClient.java:61)     org.apache.jsp.savesclient_jsp._jspService(savesclient_jsp.java:101)     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) java.lang.ClassNotFoundException:org.hibernate.HibernateException     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)     javabean.insertClient.inserisci2(insertClient.java:61)     org.apache.jsp.savesclient_jsp._jspService(savesclient_jsp.java:101)     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)

0 个答案:

没有答案