0% found this document useful (0 votes)
105 views7 pages

Hibernate JSF Login Configuration Guide

The document describes the steps to create a Java, JSF, MySQL, and Hibernate login project using NetBeans. It includes setting up the project structure, creating index.xhtml and success.xhtml pages, configuring hibernate.cfg.xml to connect to a MySQL database, implementing the Login bean class with authentication logic, and configuring faces-config.xml and web.xml files. The project allows a user to login and, upon successful authentication against the database, redirects them to a success page displaying their username.

Uploaded by

Fatema Taha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views7 pages

Hibernate JSF Login Configuration Guide

The document describes the steps to create a Java, JSF, MySQL, and Hibernate login project using NetBeans. It includes setting up the project structure, creating index.xhtml and success.xhtml pages, configuring hibernate.cfg.xml to connect to a MySQL database, implementing the Login bean class with authentication logic, and configuring faces-config.xml and web.xml files. The project allows a user to login and, upon successful authentication against the database, redirects them to a success page displaying their username.

Uploaded by

Fatema Taha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOP’s Using Java Lab I Sem MCA

Hibernate Practice

JAVA, JSF, MySql and Hibernate Login Project

Solution:
Step-1: The Project structure in Netbeans,

Complete Explanation of CA11 - [Link]

MCA - School of CS & IT Raghavendra R Asst. Prof Page 1


OOP’s Using Java Lab I Sem MCA

Step-2: [Link]

<?xml version='1.0' encoding='UTF-8' ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[Link]
<html xmlns="[Link]
xmlns:h="[Link]
<h:head>
<title>CA12</title>
</h:head>
<h:body>
<h:form>
<center> <h1>CA11 - Hibernate Login </h1>
<table border="1">
<caption>Login</caption>
<tr><td>User Name</td><td><h:inputText value="#{login_bean.user_name}"> </h:inputText>
</td></tr>
<tr><td>Password</td><td><h:inputSecret value="#{login_bean.password}"></h:inputSecret>
</td></tr>
</table>
<h:commandButton action="#{login_bean.checkuser()}" value="Submit">
</h:commandButton>
</center>
</h:form>
</h:body>
</html>

Step-3: [Link]

<?xml version='1.0' encoding='UTF-8' ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[Link]
<html xmlns="[Link]
xmlns:h="[Link]
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<font color="Green"> <b>LOGIN SUCCESSFUL</b> </font>
<br></br>

MCA - School of CS & IT Raghavendra R Asst. Prof Page 2


OOP’s Using Java Lab I Sem MCA

<br></br>
User Name is : <font color="Blue"> <b> #{login_bean.user_name} </b> </font>

</h:body>
</html>

Step-4: [Link] - This config file connects with Mysql Database

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD
3.0//EN" "[Link]
<hibernate-configuration>
<session-factory>
<property name="[Link]">[Link]</property>
<property name="[Link].driver_class">[Link]</property>
<property
name="[Link]">jdbc:mysql://localhost:3306/testlogin?zeroDateTimeBehavior
=convertToNull</property>
<property name="[Link]">root</property>
<property name="[Link]">password</property>

<mapping class="[Link]"></mapping>
</session-factory>
</hibernate-configuration>

Step-5: [Link]

package common1;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

MCA - School of CS & IT Raghavendra R Asst. Prof Page 3


OOP’s Using Java Lab I Sem MCA

import [Link];

@ManagedBean(name = "login_bean")
@SessionScoped
@Entity

public class Login implements Serializable {


@Id
private int sl_no;
private String user_name;
private String password;

public void setSl_no(int sl_no) {


this.sl_no = sl_no;
}
public int getSl_no() {
return sl_no;
}

public String getUser_name() {


return user_name;
}

public void setUser_name(String user_name) {


this.user_name = user_name;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


[Link] = password;
}

public boolean checkuser()


{
try {
[Link]("user name "+user_name);
[Link]("passowrd "+password);

MCA - School of CS & IT Raghavendra R Asst. Prof Page 4


OOP’s Using Java Lab I Sem MCA

SessionFactory sessionFactory=new
AnnotationConfiguration().configure().buildSessionFactory();
Session session=[Link]();
[Link]();
Query query=[Link]("from Login where user_name=:user_name and
password=:password");
[Link]("user_name", user_name);
[Link]("password", password);
List list=[Link]();
[Link]("list size "+[Link]());
if([Link]()==1){
return true;
}else{
return false;
}
} catch (Exception e) {
[Link](e);
}
return false;
}

public Login() {
}
}

Step-6: [Link]

<?xml version='1.0' encoding='UTF-8'?>


<faces-config version="2.2"
xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
<navigation-rule>
<from-view-id>[Link]</from-view-id>
<navigation-case>
<from-action>#{login_bean.checkuser()}</from-action>
<from-outcome>true</from-outcome>
<to-view-id>[Link]</to-view-id>
<redirect></redirect>

MCA - School of CS & IT Raghavendra R Asst. Prof Page 5


OOP’s Using Java Lab I Sem MCA

</navigation-case>
<navigation-case>
<from-action>#{login_bean.checkuser()}</from-action>
<from-outcome>false</from-outcome>
<to-view-id>[Link]</to-view-id>
<redirect></redirect>
</navigation-case>
</navigation-rule>

</faces-config>

Step-7: [Link]

<?xml version="1.0" encoding="UTF-8"?>


<web-app version="3.1" xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link] [Link]
app_3_1.xsd">
<context-param>
<param-name>[Link].PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>[Link]</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/[Link]</welcome-file>
</welcome-file-list>
</web-app>

MCA - School of CS & IT Raghavendra R Asst. Prof Page 6


OOP’s Using Java Lab I Sem MCA

Output:

MCA - School of CS & IT Raghavendra R Asst. Prof Page 7

You might also like