Home Discussion Discuss: JSF Simple Login Application

  • Query regarding jsf 1.2 loginbheem vimal October 25, 2011 at 9:08 PM

    i got same problem.please assist me. my directory structure is as webapps-->JsfMysql1 -->(pages directory & WEB-INF directory) pages-->(login.jsp,success.jsp,fail.jsp) WEB-INF-->(src & lib directory and web.xml & faces-config.xml) src-->java-->mydbtest-->login-bean.java --------------------------------------------------------------- code for "login .jsp" is as: ------------------------------------------------------------------------------------------ <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Data Connectivity</title> </head> <link rel="stylesheet" type="text/css" href="CSS/style.css"> <body> <f:view> <h:form id="f1"> <h2>Login Please:</h2> <table width="250" border="0" cellspacing="0" cellpadding="2"> <tr> <td colspan="2"> <h:message for="username" styleClass="errorMsg"/><br> <h:message for="password" styleClass="errorMsg"/> </td> </tr> <tr> <td><h:outputText value="Username : "/></td> <td><h:inputText id="username" value="#{login_bean.username}" required="true" styleClass="input_text"/></td> </tr> <tr> <td><h:outputText value="Password : "/></td> <td><h:inputSecret id="password" value="#{login_bean.password}" required="true" styleClass="input_text"/></td> </tr> <tr> <td colspan="2" align="center"> <h:commandButton action="#{login_bean.checkValidUser}" value="Login" type="submit"/></td> </tr> </table> </h:form> </f:view> </body> </html> ------------------------------------------------------------------------ code of "login-bean.java" ----------------------------------------------------------------- package mydbtest; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import java.sql.*; import java.util.*; @ManagedBean(name="login_bean") @RequestScoped public class login_bean { private String username; private String dbpassword; private String password; private String dbusername; public String getDbpassword() { return dbpassword; } public String getDbusername() { return dbusername; } Connection con; Statement ps; ResultSet rs; String SQL_Str; public void dbData(String UName) { try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/logintest","root","vimal"); ps = con.createStatement(); SQL_Str="Select * from login where UName like ('" + UName +"')"; rs=ps.executeQuery(SQL_Str); rs.next(); dbusername=rs.getString(1).toString(); dbpassword=rs.getString(2).toString(); } catch(Exception ex) { ex.printStackTrace(); System.out.println("Exception Occur :" + ex); } } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String checkValidUser() { dbData(username); if(username.equalsIgnoreCase(dbusername)) { if(password.equals(dbpassword)) return "valid"; else { return "invalid"; } } else { return "invalid"; } } } ------------------------------------------------------------------------------------ code of "faces-config .xml" ----------------------------------------------------------------------------- <?xml version='1.0' encoding='UTF-8'?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd" version="1.2"> <managed-bean> <managed-bean-name>login_bean</managed-bean-name> <managed-bean-class>mydbtest.login_bean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <navigation-rule> <description>Loging Page</description> <from-view-id>pages/login.jsp</from-view-id> <navigation-case> <from-action>#{login_bean.checkValidUser}</from-action> <from-outcome>valid</from-outcome> <to-view-id>pages/success.jsp</to-view-id> </navigation-case> <navigation-case> <from-action>#{login_bean.checkValidUser}</from-action> <from-outcome>invalid</from-outcome> <to-view-id>/pages/fail.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <description>ReLoging Page</description> <from-view-id>/pages/fail.jsp</from-view-id> <navigation-case> <from-action>#{login_bean.checkValidUser}</from-action> <from-outcome>valid</from-outcome> <to-view-id>/pages/success.jsp</to-view-id> </navigation-case> <navigation-case> <from-action>#{login_bean.checkValidUser}</from-action> <from-outcome>invalid</from-outcome> <to-view-id>/pages/fail.jsp</to-view-id> </navigation-case> </navigation-rule> <application> <message-bundle>messages.message</message-bundle> </application> </faces-config> -------------------------------------------- code of "web.xml" -------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/pages/login.jsf</welcome-file> </welcome-file-list> </web-app> --------------------------------------- code of "success.jsp" --------------------------------------------------------- <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>SuccessPage</title> </head> <body> <f:view> <h:form> <h2>Hello <h:outputText value="#{login_bean.username}"/>, you are successfully login.</h2> </h:form> </f:view> </body> </html> ------------------------------------------------- code of "fail.jsp" ------------------------------------------------------------- <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>LOGIN</title> </head> <link rel="stylesheet" type="text/css" href="CSS/style.css"> <body> <f:view> <h:form id="login_frm"> <h2>Login Please:</h2> <table width="250" border="0" cellspacing="0" cellpadding="2"> <tr> <td colspan="2"> Incorrect Username or Password!!<br> <h:message for="username" styleClass="errorMsg"/><br> <h:message for="password" styleClass="errorMsg"/> </td> </tr> <tr> <td><h:outputText value="Username : "/></td> <td><h:inputText id="username" value="#{login_bean.username}" required="true" styleClass="input_text"/></td> </tr> <tr> <td><h:outputText value="Password : "/></td> <td><h:inputSecret id="password" value="#{login_bean.password}" required="true" styleClass="input_text"/></td> </tr> <tr> <td colspan="2" align="center"> <h:commandButton action="#{login_bean.checkValidUser}" value="Login" type="submit"/></td> </tr> </table> </h:form> </f:view> </body> </html> ---------------------------------------------------------------------------------- database name: logintest table name: login table attribute is uname varchar(11) upass varchar(11) ------------------------------------------------------------------------------------- I tried this above code for jsf 1.2 It runs but not displaying any meassage like login success or fail It stucks on login .jsp page. Please assist me soon.

  • Very good one bala December 22, 2011 at 11:20 AM

    Nice website to learn

  • Navigation not working.Arunprasad April 10, 2012 at 2:23 PM

    In this above program . i can't perform navigation i.e.After click the login button next page doesn't open(success or Failure) again shows the login page

  • post links missingsam April 24, 2012 at 6:50 AM

    You have not provided the links for resultforfail.jsp and resultforsuccess.jsp..and downloading you application doesn't help either, those files r missing..

  • textnour June 23, 2012 at 6:39 AM

    hello, I am newbie in jsf I want to secure my application with a session but I ais no EDEE how gere in jsf qulque helps me, thank you

  • login applicationmdmeraj July 10, 2012 at 8:39 PM

    login name and password example u can search in php c# and vb.net and also this

  • jpa jsfoumayma bounouh July 26, 2012 at 7:04 PM

    plz, i have already done this exemple, and it runs correctly. but if i have a database how could I check or verify if the login and the password exist in this Data base or not? (I have used JPA)... Sincerly

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
JSP Servlet Questions

login application
login application  how to create login application ?   Hi, Please check the following tutorials: Video tutorial - JSP Login Logout Example Login Authentication using Bean and Servlet In JSP simple code to login user 

JSF Tutorials & Examples

JSF Simple Login Application
;http://java.sun.com/jsf/core" prefix="f"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <f:view> <html> <head><title>JSF Simple Login Example< 

Java Server Faces Questions

JSF Simple Login Application - Java Server Faces Questions
JSF Simple Login Application  Hi there, I have implemented all the things which you mentioned in " JSF Simple Login Application " . but as i insert USER_ID and PASSWORD then it is showing an exception which 

Struts Examples

Login Application
Login Application       This tutorial provides some simple steps for creating a website login application that can be used later in any big Struts Hibernate and Spring based 

Struts Examples

Struts 2 Login Application
. Steps to develope the application Here are simple and easy steps to develop Login...Struts 2 Login Application       Developing Struts 2 Login Application In this section we are going to develop 

Java Beginners

Simple Login(JSF)
Simple Login(JSF)  I have tried to run the Simple Login code provided using netbeans. It gives me error. CAn I run it using netbeans or need to config anything in order to run the prog 

JSP Tutorials

Simple Bank Application in JSP
Simple Bank Application in JSP       In this section, we have developed a simple bank application in jsp . In this application user can Update the User Profile, Cash 

JSF Tutorials & Examples

JSF Validation In Login Application
;http://java.sun.com/jsf/core" prefix="f"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <f:view> <html> <head><title>JSF Simple Login Example< 

Spring Framework Questions

Spring login form application
Spring login form application  Hi Please give me the Spring login form application so that i can understand its flow ?   Hi please find the link of the tutorial Spring Applications 

Struts Questions

login application - Struts
login application  Can anyone give me complete code of user login application using struts and database?  Hello, Here is good example of Login and User Registration Application using Struts Hibernate and Spring 

JSP Servlet Questions

jsp login page
jsp login page  Hi All, can any one tell me how to create Login page using JSP and Beans. A simple log in page. Please reply ASAP. Thanx, am2085   Hello Friend, Please visit the following link: JSP Login Using 

JSP-Tutorials

JSP Login Logout Example
a simple login and logout example. This section will describe you all the steps for creating a simple login and logout example. To create a simple login logout... interface i.e. login form. Example I am giving here a simple login logout 

Hibernate Questions

Simple application using hibernate
Simple application using hibernate  Hi, How to write a simple application using hibernate in Eclipse IDE? I would like to to learn: Process... of the tutorial you will like to learn for creating the simple application using 

Struts Questions

Regarding Login application program
Regarding Login application program  Hi this is shiva. iam writing a small login form using struts1.3.10 version. once iam submit the login button... it is giving java.lang.NullPointerException exception. Please download the login form 

Java Beginners

iframe application facebook login
iframe application facebook login  Create link to facebook from iFrame application 

Spring Framework Questions

java spring simple application
java spring simple application  hai I have design a simple application in this I always found class not found exception. I am sendig code as follows please resolve this and send me.my directory structure is as follows Project 

Java Server Faces

User Login and Registration application
User Login and Registration application   ... explanation of the application in JSF ( Apache MyFaces) with the combined help... an application using different frameworks. This application starts from user 

Java Beginners

Simple Java Desktop Upload application
Simple Java Desktop Upload application  I try do simple example for upload applicationtake file from c:\ put to d:\ :) PLEASE HELP 

Java Beginners

Simple IO Application - Java Beginners
Simple IO Application  Hi, please help me Write a simple Java application that prompts the user for their first name and then their last name. The application should then respond with 'Hello first & last name, what 

JSP Servlet Questions

simple bank application - JSP-Servlet
simple bank application  hi i got ur codings...But if we register a new user it is not updating in the database...so plz snd me the database also.... Thank you 

Applet Questions

Simple Java applet that need usernam, password and textfield.
Simple Java applet that need usernam, password and textfield.  Hi. Anyone can help me on this matter: I need to create a small application that require user to login by username and password. After login, they should meet 

JSP Servlet Questions

simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks 

Struts 2 Tutorials

Module In An Application
Modules in a Application Modules and there feature in the present application are as follows- Customer Module Customer Registration Customer Login View Products with Buy Options Search product Category wise Calculate 

J2EE

Creating Midlet Application For Login in J2ME
Creating MIDlet Application For Login in J2ME  ... application for user login . All MIDlet applications for the MIDP ( Mobile Information... as a mediator between the application and the environment in which the application runs 

Spring Framework Questions

getting classnotfound exception while running login application
running the Login Application   Have a look at the following link: Spring Login Application...getting classnotfound exception while running login application  hi 

WebSevices Questions

create login java web service - WebSevices
create login java web service  Hi, I am kind of newb in java web service development , i want to write a simple web service application that client send username and password for server , then after authenticate that with mysql 

Struts Questions

Login - Struts
Struts Login page  I want to page in which user must login to see that page. I can do that simple but he/she know that page URL,he/she can simplely type that url... Login Page after logging that page must return to my page.please 

HTML Questions

How to use css in simple HTML application
How to use css in simple HTML application   Please give simple example for understanding purpose 

Struts 2 Tutorials

About Struts 2.2.1 Login application
.style1 { margin-left: 80px; } About Struts2.2.1 login application In the most common login application there is  login form which is takes... / browser. To create an login application At first create a login page in JSP 

JSF Tutorials & Examples

RichFaces: Login & Registration Application:
RichFaces: Login & Registration Application  ... functionality in your JSF project. The example application in this tutorial... the responsiveness of the application. In this application, Login page appears first 

DMCA.com