hi All, I am new to hibernate. I am using eclipse3.4.1 ide. eclipse3.4.1 doesn't support hibernate. So,I have installed the plugin hibernate synchronizer. please answer the question.
I have written the code for spd.jsp below
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="org.students.hyd.Product"%> <%@page import="org.hibernate.*"%> <%@page import="org.hibernate.cfg.Configuration"%> <%@page import="org.hibernate.Session"%>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title></title> </head> <body>
<% String vprodid=request.getParameter("prodid"); String vprodname=request.getParameter("prodname"); String vprice=request.getParameter("prodprice");
Session hsession=null; Configuration conf=new Configuration(); System.out.println("Configuration conf=new Configuration();\n"); conf.configure(); System.out.println("conf.configure();\n"); SessionFactory sessionFactory=conf.buildSessionFactory(); System.out.println("SessionFactory sessionFactory=conf.buildSessionFactory();\n"); hsession=sessionFactory.openSession(); System.out.println("session=sessionFactory.openSession();\n"); Transaction tx = hsession.beginTransaction(); org.students.hyd.Product prod =new org.students.hyd.Product(); prod.setProdId(new Integer(vprodid)); prod.setProdName(new String(vprodname)); prod.setPrice(new Float(vprice)); hsession.save(prod); tx.commit(); hsession.close();
%>
<%=vprodid%> <%=vprodname%> <%=vprice%> <a href="menu.html">main form </a> </body> </html>
I am getting error like this:
description :The server encountered an internal error () that prevented it from fulfilling this request.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the generated java file Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package
An error occurred at line: 9 in the generated java file Only a type can be imported. org.hibernate.Session resolves to a package
An error occurred at line: 23 in the jsp file: /spd.jsp Session cannot be resolved to a type 20: String vprodname=request.getParameter("prodname"); 21: String vprice=request.getParameter("prodprice"); 22: 23: Session hsession=null; 24: Configuration conf=new Configuration(); 25: System.out.println("Configuration conf=new Configuration();\n"); 26: conf.configure();
An error occurred at line: 24 in the jsp file: /spd.jsp Configuration cannot be resolved to a type 21: String vprice=request.getParameter("prodprice"); 22: 23: Session hsession=null; 24: Configuration conf=new Configuration(); 25: System.out.println("Configuration conf=new Configuration();\n"); 26: conf.configure(); 27: System.out.println("conf.configure();\n");
An error occurred at line: 24 in the jsp file: /spd.jsp Configuration cannot be resolved to a type 21: String vprice=request.getParameter("prodprice"); 22: 23: Session hsession=null; 24: Configuration conf=new Configuration(); 25: System.out.println("Configuration conf=new Configuration();\n"); 26: conf.configure(); 27: System.out.println("conf.configure();\n");
An error occurred at line: 28 in the jsp file: /spd.jsp SessionFactory cannot be resolved to a type 25: System.out.println("Configuration conf=new Configuration();\n"); 26: conf.configure(); 27: System.out.println("conf.configure();\n"); 28: SessionFactory sessionFactory=conf.buildSessionFactory(); 29: System.out.println("SessionFactory sessionFactory=conf.buildSessionFactory();\n"); 30: hsession=sessionFactory.openSession(); 31: System.out.println("session=sessionFactory.openSession();\n");
An error occurred at line: 33 in the jsp file: /spd.jsp Transaction cannot be resolved to a type 30: hsession=sessionFactory.openSession(); 31: System.out.println("session=sessionFactory.openSession();\n"); 32: 33: Transaction tx = hsession.beginTransaction(); 34: org.students.hyd.Product prod =new org.students.hyd.Product(); 35: prod.setProdId(new Integer(vprodid)); 36: prod.setProdName(new String(vprodname));
Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423) org.apache.jasper.compiler.Compiler.compile(Compiler.java:316) org.apache.jasper.compiler.Compiler.compile(Compiler.java:294) org.apache.jasper.compiler.Compiler.compile(Compiler.java:281) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
|