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
You have not provided the links for resultforfail.jsp and resultforsuccess.jsp..and downloading you application doesn't help either, those files r missing..
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
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