Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSF Simple Login Application 
 

This is the login application in which you will get the complete login facilities whatever should be in a web based application for protecting the page or the website accessibility. This application provides authentication for accessing application after

 

JSF Simple Login Application

                          

This is the login application in which you will get the complete login facilities whatever should be in a web based application for protecting the page or the website accessibility. This application provides authentication for accessing application after successful login. For accessing the application everyone should have a user id and a password regarding of that.

This application is very useful for developing any type of web based application in which login application is needed. Here Roseindia provides you a complete login application in the JSF Tutorial section to teach you JSF by examples. You are here after getting all the theoretical concepts from the previous section of the Roseindia JSF Tutorial. If you have already completed all the theoretical concepts from the Roseindia JSF Tutorial then OK otherwise first you should complete previous sections from the Roseindia JSF Tutorial.

Here, you are going to study the JSF Login Application that is simply for the login purpose that illustrates you about the procedure of developing applications in JSF. You will know how JSF works after following the example.

This section here provides you a simple but the important thing for protecting your any type of web application that makes your website or application secure. This application is simply used for providing the facility for accessing the application by getting authentication.

When you run the application, this application will tell you for entering your login Id and Password. If you enter wrong login id or password it will show you for "Login failed!" and if you enter the correct login id and password then the application shows the message "Login Successful!". For logging the application first you have to know your login id and password which are given as follows:

Login ID: chandan
Password: chand

Now, you can enter in your application by using the login page.

For running your application you will have to copy the complete application folder in your tomcat/webapps directory after extracting the downloaded zip file. And type the url: http://localhost:8080/SimpleLogin/login.jsf in your browser.

Output of Simple Login Application:

If you enter wrong login id or password then the application shows the output like the following image:

And if you enter correct login id and password then the application shows the output like as follows:

There are some files have been used for constructing the application. These files have been explained as follows:

Here is the code for the login.jsp file:

<%@ page contentType="text/html"%>
<%@ taglib uri="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</title></head>
		
		<body>
			<h:form>
				<table>
					<tr>
						<td><h:outputText value
="Enter Login ID: " /></td>
						<td><h:inputText id=
"loginname" value="#{SimpleLogin.loginname}" /></td>
					</tr>
					<tr>
						<td><h:outputText value=
"Enter Password: " /></td>
						<td><h:inputSecret id=
"password" value="#{SimpleLogin.password}" /></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><h:commandButton value=
"Login" action="#{SimpleLogin.CheckValidUser}" /></td>
					</tr>
				</table>
			</h:form>
		</body>
	</html>
</f:view>

Here is the code for the resultforfail.jsp file:

Login Failed!

Here is the code for the resultforsuccess.jsp file:

Login Successful!

Here is the code for the Backing Bean SimpleLogin.java file:

package roseindia;

public class SimpleLogin{
	String loginname;
	String password;

	public SimpleLogin(){}

	public String getLoginname(){
		return loginname;
	}

	public void setLoginname(String loginname){
		this.loginname = loginname;
	}

	public String getPassword(){
		return password;
	}

	public void setPassword(String password){
		this.password = password;
	}

	public String CheckValidUser(){
		if(loginname.equals("chandan") && password.equals("chand")){
			System.out.println("chandan");
			return "success";
		}
		else{
			return "fail";
		}
	}
}

faces-config.xml file code:


<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
	<managed-bean>
		<managed-bean-name>SimpleLogin</managed-bean-name>
		<managed-bean-class>roseindia.SimpleLogin</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<navigation-rule>
		<from-view-id>/login.jsp</from-view-id>
		<navigation-case>
			<from-action>#{SimpleLogin.CheckValidUser}</from-action>
			<from-outcome>success</from-outcome>
			<to-view-id>resultforsuccess.jsp</to-view-id>
		</navigation-case>
		<navigation-case>
			<from-action>#{SimpleLogin.CheckValidUser}</from-action>
			<from-outcome>fail</from-outcome>
			<to-view-id>resultforfail.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
</faces-config>

web.xml file code:

<?xml version="1.0"?> 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>    

    <!-- 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>
</web-app>

Download This Complete Application.

                          

» View all related tutorials
Related Tags: c com memory server dynamic tree components core component tag name this node oo ibm create root like for example

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

6 comments so far (
post your own) View All Comments Latest 10 Comments:

hi friends,
How to link the one file to next.please help

Posted by nithi on Thursday, 12.18.08 @ 23:48pm | #82947

JSF MaterialJSF Material

Posted by Syamu on Monday, 06.9.08 @ 13:00pm | #62696

i am getting the below error message,can any one please advise,

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

javax.servlet.ServletException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.index_jsp._jspService(index_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

javax.servlet.jsp.JspException: Cannot find FacesContext
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:405)
com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
org.apache.jsp.index_jsp._jspx_meth_f_view_0(index_jsp.java:95)
org.apache.jsp.index_jsp._jspService(index_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

Posted by Subbu on Monday, 05.5.08 @ 20:55pm | #58553

this material is very good. thank u rose india for providing this one

Posted by Samuel on Saturday, 09.22.07 @ 12:54pm | #28842

Hi, Amit
You can go to the another one page after successing the login by using the action managed by the faces-config.xml file or you can also use the FacesContext class for refering to the another page.
Syntax is given below that has to be used in the backing bean class.

FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().redirect(context.getExternalContext().getContextPath() + "/yourpage.jsf");

Thanks & Regards
Chandan Kumar Verma
Roseindia Member

Posted by chandan kumar verma on Sunday, 07.1.07 @ 11:56am | #20503

hi, yours article is nice, the way it has been given is easly understandable. But one thing I want to ask you that, on login page when I login successfuly then only I should get the success page but even when I am giving the URL for success page I am geting it which should not happen. Can you suggest me solution for it.

Posted by Amit Kumar on Friday, 06.8.07 @ 14:54pm | #18590

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.