Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to do registration form using struts and hibernate?

Answer Posted / suyog

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">

<!-- Generated by MyEclipse Hibernate Tools.
-->
<hibernate-configuration>

<session-factory>
<property
name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property
name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="connection.username">system</property>
<property name="connection.password">system</property>
<property
name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<mapping resource="Registration.hbm.xml"/>
</session-factory>

</hibernate-configuration>






Registration.java

package mypack;

public class Registration {
int id;
String name,password,email;


public Registration() {
super();

}
public Registration(String name, String password, String
email) {
super();
this.name = name;
this.password = password;
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}



}



Registration.hbm.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.
-->
<hibernate-mapping>
<class name="mypack.Registration">
<id name="id" type="int">
<generator class="increment"></generator>
</id>
<property name="name"/>
<property name="password"/>
<property name="email"/>
</class>


</hibernate-mapping>



DAO.java


package mypack;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class DAO {

public void insert(Object o)
{
Configuration cfg=new Configuration().configure();
SessionFactory f=cfg.buildSessionFactory();
Session session=f.openSession();
Transaction t=session.beginTransaction();
session.save(o);
t.commit();
session.close();

}
}


index.jsp




<%@ taglib uri="/struts-tags" prefix="s"%>
<s:form action="Reg">
<s:textfield name="r.name" label="name"></s:textfield>
<s:textfield name="r.password" label="password"></s:textfield>
<s:textfield name="r.email" label="email"></s:textfield>
<s:submit value="register"></s:submit>

</s:form>





a.jsp

<b>successfully inserted</b>






strut.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="Reg" class="mypack.RegistrationAction">
<result name="success">/a.jsp</result>
</action>
</package>
</struts>




RegisterAction.java

package mypack;

public class RegistrationAction {

Registration r;
public String execute()
{
DAO dao=new DAO();
dao.insert(r);
return "success";

}
public Registration getR() {
return r;
}
public void setR(Registration r) {
this.r = r;
}


}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How substring() method of string class create memory leaks?

1042


What is the purpose of the notifyall() method?

1041


What is bean? Where can it be used?

1159


How primary key is implemented in Oracle?

2439


the same information whether it will connect to the database or it will be used previous information?

1035


Where can I find seam examples and documentation?

1088


Name the class that is used to bind the server object with RMI Registry?

2158


What is in-memory replication?

1054


Why are some of the class and element names counter-intuitive?

1140


Why use a datasource when you can directly specify a connection details?

1022


What are the services in RMI ?

2349


we use MainFrame and using os390 for operating system with DB2 data base in IRAN and interest programing with java and use webspere for world wide,please help me where i should start?

2416


Why do I get a duplicate name error when loading a jar file?

1137


AS a developer will u create a data source in connection pool? If so how will u do that, how to access the object from connection pool using IRAD tool?

2140


How are the elements of a cardlayout organized?

1079