how to send the form data to database using servlets and hibernate???????
m getting org.hibernate.Session. showing ClassNotFoundException..
help!!!!!!!!!!!!!!!!!
mycode:
login.jsp
<form action="Servlet" >
id
<input type="text" name="id"></br>
username
<input type="text" name="username"></br>
lastname
<input type="text" name="lastname"></br>
<input type="submit" value="submit">
</form>
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver. OracleDriver</property>
<property name="connection.url">jdbcracle:thin:@localhost:1521:XE</property>
<property name="connection.username">system</property>
<property name="connection.password">system</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect </property>
<!-- Enable Hibernate's current session context -->
<property name="current_session_context_class">org.hibernate .context.ManagedSessionContext</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.No CacheProvider</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">update</property>
<mapping resource="com/com/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Pojo:
Person.java
package com.com;
public class Person {
private String id;
private String username;
private String lastname;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}
servlet.java
package com.com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Servlet implementation class Servlet
*/
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
String s1=request.getParameter("id");
String s2=request.getParameter("username");
String s3=request.getParameter("lastname");
Session s=HibernateUtil.getSession();
Person p=new Person();
//p.setId(s1);
p.setUsername(s2);
p.setLastname(s3);
s.beginTransaction();
s.save(p);
s.getTransaction().commit();
s.flush();
s.close();
System.out.println("done");
out.print("done");
out.close();
}
}