Java Server Page

JSP Projects

JSP Project

adplus-dvertising
Write the program for Email validation and store, display information of user
Previous Home Next
Save that as Registration.html

Note: This page contain only input field.

Following program contain Email validation in JSP using JavaBeans to Understand

how program is flow consider program flow diagram

Here our first program. Save as LoginFile.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>R4R CO IN</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
 <H1 style="font-size: 20pt;font-style: inherit;color: green">
 R4R Tech Soft!Login File</H1>
  <H2 style="font-size: 15pt;font-style: italic; color: teal">
  Please enter your detail, 
		then press submit</H2>
 <!--Script is used for
 the check,validation,condition within that page-->
<script 
type="text/javascript">
        function dd(){
//call the Registration.html page
document.LoginFile.action="Registration.html";
document.LoginFile.submit();
}
function check(){
    if(document.LoginFile.userName.value==null||
					document.LoginFile.userName.value=="")
    {
        alert("Please Enter the UserName:");
        return false;
    }else
        if(document.LoginFile.password.value==null||
					document.LoginFile.password.value=="")
    {
        alert("Please Enter the Password:");
        return false;
    }else{document.LoginFile.submit();}
}
        </script>
        <form method="post" name="LoginFile" action="Login.jsp">
<BR>Enter your UserName:
<input type="text" size="20" name="userName" 
			value="" maxlength="15">
<BR><BR>Enter Your Password:
<input type="password" size="20" name="password" 
			value="" maxlength="15">
<BR><BR>
<input type="button" name="submit1" value=" Submit "
			onclick="check()">
<input type="Reset" name="reset" value="  Reset ">
<BR><BR>
  <input type="button" name="newUser" value="   NewUser  " 
			  onclick="dd(this)">
// New user please press newUser button for registration....
        </form>
    </body>
</html>
Second program. Save as Registration.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>R4R CO IN</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<H1 style="font-size: 20pt;font-style: inherit;color: green">
		R4R Tech Soft!Registration File</H1>
<H2 style="font-size: 15pt;font-style: italic; color: teal">
		Please enter your detail, then press submit</H2>

<!-- JavaScript is used for the check,
validation,condition within that page-->
<script>
function check(){
if(document.Registration.userName.value==null||document.
			Registration.userName.value=="")
{
alert("Please Enter the UserName:");
return false;
}else
if(document.Registration.password.value==null||document.
					Registration.password.value=="")
{
alert("Please Enter the Password :");
return false;
}else
if(document.Registration.firstName.value==null||document.
					Registration.firstName.value=="")
{
alert("Please Enter the FirstName:");
return false;
}else
if(document.Registration.lastName.value==null||document
					.Registration.lastName.value=="")
{
alert("Please Enter the LastName:");
return false;
}else
if(document.Registration.phone.value==null||document.
					Registration.phone.value=="")
{
alert("Please Enter the Phone/Mobile:");
return false;
}else
if(document.Registration.email.value==null||document.
					Registration.email.value==""){
alert("Please Enter the Email ID:");
return false;
}
else { document.Registration.submit();}
}
</script>
<form method="post" action="Registration.jsp" name="Registration">
<BR>Chose your UserName:
<input type="text" size="20" name="userName" value="" maxlength="15">
<BR><BR>Chose Your Password:
<input type="password" size="20" name="password" value="" maxlength="15">
<BR><BR>Enter your FirstName:
<input type="text" size="20" name="firstName" value="" maxlength="10">
<BR><BR>Enter your LastName:
<input type="text" size="20" name="lastName" value="" maxlength="10">
<BR><BR>Enter your Phone/Mobile:
<input type="text" size="20" name="phone" value="" maxlength="15">
<BR><BR>Enter your Email ID:
<input type="text" size="20" name="email" value="" maxlength="20">
<BR><BR>
&nbsp; &nbsp;<input type="Submit" name="submit11" value=" Submit " 
			onclick="check()">
&nbsp;<input type="Reset" name="reset" value=" Reset ">
</form>
</body>
</html>
Third Program, Save as Registration.jsp
<%--Save as a Regstration.jsp--%>
<%-- This is main file, contain first page LoginFile.html--%>
<%@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">
<! Here Import shows direct path of infobeans to compiler>
<%@page  errorPage="error.jsp"
import="java.util.*,r4r.co.in.infoBeans"%>
<html>
 <head><meta http-equiv="Content-Type" 
 content="text/html; charset=UTF-8">
 <title>R4R CO IN</title>
     </head>
 <body>
 <%-- Import file LoginFile.html  --%>
 <%@include file="LoginFile.html" %>
  <%
  //Taking parameter from Registration.html
  String userName = (String) request.getParameter("userName");
  String password = (String) request.getParameter("password");
  String firstName = (String) request.getParameter("firstName");
  String lastName = (String) request.getParameter("lastName");
  String phone = (String) request.getParameter("phone");
  String email = (String) request.getParameter("email");
   %>
     <%--Store all the parameter from the Registration.html 
		   to the infoBeans.java Which create a HTTPSESSION and store
		   all parameter in it.class represent the path of Bean
		   (infoBean is created into r4r.co.in (packages).--%>
<jsp:useBean id ="infoBeans" scope="session" 
				  class="r4r.co.in.infoBeans" >
</jsp:useBean>
   <%-- All parameter set into session using infoBeans.java  --%>
   <jsp:setProperty name="infoBeans" property="userName" 
	value="<%=userName%>" />
   <jsp:setProperty name="infoBeans" property="password" 
	value="<%=password%>" />
  <jsp:setProperty name="infoBeans" property="firstName"
	value="<%=firstName%>" />
   <jsp:setProperty name="infoBeans" property="lastName"
	value="<%=lastName%>" />
  <jsp:setProperty name="infoBeans" property="phone"
	value="<%=phone%>" />
   <jsp:setProperty name="infoBeans" property="email" 
	value="<%=email%>" />
    <%--   check the condition on submit button is press  --%>
  <%
  if (request.getParameter("submit11") != null) {
//Call the page LoginFile.html (using sendRedirect)
String destination = "LoginFile.html";
response.sendRedirect(destination);
  } else {
//Due to JAVASCRIPT else condition never call
  }
	 %>
     </body>
  </html>
Fourth program, Save as Login.jsp
<%--Save as a Login.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">
<%@page errorPage="error.jsp" import="java.util.*" %>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html;
	   charset=UTF-8">
  <title>R4R CO IN</title>
  </head>
  <body>
  <H1 style="font-size: 20pt;font-style:italic; 
	   color: purple">
		 R4R Tech Soft!RESULT DISPAY</H1>
<%
  //Taking the parameter from LoginFile.html
  String userName = (String) request.getParameter("userName");
  String password = (String) request.getParameter("password");
   %>
   <%-- Store all the parameter from the LoginFile.
   html to the loginBeans.java
    Which create a HTTPSESSION and store all parameter in it.
    class represent the path of Bean(infoBean is created
		 into r4r.co.in (packages)--%>
  <jsp:useBean id="loginBeans" scope="session" 
				 class="r4r.co.in.loginBeans">
  </jsp:useBean>
 <%-- All parameter set into session using infoBeans.java  --%>
  <jsp:setProperty name="loginBeans" property="userName" 
	value="<%=userName%>"/>
 <jsp:setProperty name="loginBeans" property="password"value=
"<%=password%>" />
   <%--
 call the infoBeans.java
 Help to create the instance of infoBeans	--%>
<jsp:useBean id="infoBeans" scope="session" 
class="r4r.co.in.infoBeans">
</jsp:useBean>
   <%
/* Create a instance of infoBeans.java(called as s)
Due to instance it allow to use all the parameter here*/
r4r.co.in.infoBeans s = (r4r.co.in.infoBeans)
		session.getAttribute("infoBeans");
  //Check the condition and print result
 if (userName.equals(s.getUserName()) &&
	 password.equals(s.getPassword())) {
   out.println("Authentication presion,Hello:" 
	   + s.getFirstName());
   out.println("<BR><BR>Detail of the Persion");
   out.println("<BR>UserName: " +  s.getUserName());
   out.println("<BR>PassWord: " +  s.getPassword());
   out.println("<BR>FirstName: " +  s.getFirstName());
   out.println("<BR>LastName: " +  s.getLastName());
   out.println("<BR>Phone/Mobile: " +  s.getPhone());
   out.println("<BR>Email ID: " +  s.getEmail());
  } else {
	out.println("Sorry, Unauthentication persion:" 
		+ s.getFirstName());
   }
   %>
 </body>
  </html>
Fifth Program. Save as error.jsp
<%--Save as a error.jsp--%>
<%-- This page is used to display and handle any
error occure within the Project(r4r)--%>
<%@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">
<%@page  isErrorPage="true" import="java.util.*"%>
  <html>
<head>
<meta http-equiv="Content-Type" content="text/html;
	 charset=UTF-8">
 <title>R4R CO IN</title>
</head>
<body>
 <H1 style="font-size: 20pt;font-style: inherit;color: green">
		R4R Tech Soft!Error generate</H1>
 Error Occured
 <!Provide all the detail about the error >
 <%= exception.toString() %>
</body>
</html>
Sixth Program, Save as infoBeans.java

//Save as a infoBeans.java

//Package name r4r.co.in

package r4r.co.in;

// infoBeans is created for store value from 
//  Registration.html to HTTPSESSION 
public class infoBeans {
   private String userName;
   private String password;
   private String firstName;
   private String lastName;
   private String phone;
   private String email;
   public String getUserName() {
         return userName;
       }
      public void setUserName(String userName) {
       this.userName = userName;
   }
      public String getPassword() {
       return password;
   }
      public void setPassword(String password) {
       this.password = password;
    }
      public String getFirstName() {
        return firstName;
   }
      public void setFirstName(String firstName) {
      this.firstName = firstName;
    }
      public String getLastName() {
        return lastName;
    }
      public void setLastName(String lastName) {
        this.lastName = lastName;
   }
      public String getPhone() {
       return phone;
    }
      public void setPhone(String phone) {
        this.phone = phone;
    }
     public String getEmail() {
        return email;
    }
     public void setEmail(String email) {
       this.email = email;
    }
  }
Seventh Program, Save as loginBeans.java

//Save as a loginBeans.java

//Package name r4r.co.in

package r4r.co.in;
// loginBeans is created for store value from
 // LoginFile.html to HTTPSESSION
public class loginBeans {
    private String username;
    private String password;
    public String getUserName(){
        return username;
    }
    public void setUserName(String username){        
        this.username=username;
    }
    public String getPassword(){
        return password;
    }
    public void setPassword(String password){
        this.password=password;
    }
  }
Output:
Previous Home Next