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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Developing User Registration Form 
 

This section takes you through the steps necessary to develop the User Registration Form for our Struts, Hibernate and Spring based User Registration and Authentication Application.

 

Developing User Registration Form

                         

This section takes you through the steps necessary to develop the User Registration Form for our Struts, Hibernate and Spring based User Registration and Authentication Application. This section shows you how to develop the User Registration Form and related JSP files.

This User Registration section of application is composed of two Views. 

  1. Registration Form: Registration Form displays the fields to take the necessary input from the user. 
      
  2. Result Page: The result page displays the message that indicates success. If the there is some error while registering the user, Registration Form is displayed again indicating the error occurred during the registration process.

The necessary code are described further down in this section.

Registration JSP (userRegister.jsp)

The Registration JSP (userRegister.jsp) generates the registration form and displayed to the user to take the input.

Here is the code of the userRegister.jsp file:

 <%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:html locale="true">

<head>
<LINK rel="stylesheet" type="text/css" name="anyname" href="<html:rewrite page='/css/style.css'/>">
<title></title>
<html:base/>
<SCRIPT LANGUAGE=javascript>

function checkEmail(email) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false);
}


function validateForm(formObj){

if(formObj.userid.value.length==0){
alert("Please enter User ID!");
formObj.userid.focus();
return false;
}

if(formObj.password.value.length==0){
alert("Please enter password!");
formObj.password.focus();
return false;
}

if(formObj.email.value.length==0){
alert("Please enter Email!");
formObj.email.focus();
return false;
}

if(!checkEmail(formObj.email.value)){
   formObj.email.focus();
   return false;
}

if(formObj.address.value.length==0){
alert("Please enter address!");
formObj.address.focus();
return false;
}

if(formObj.phno.value.length==0){
alert("Please enter Phone No.!");
formObj.phno.focus();
return false;
}

if(isNaN(formObj.phno.value)){
alert("Please enter correct Phone No!");
formObj.phno.focus();
return false;
}


formObj.actionUpdateData.value="update";
return true;
}
//-->
</SCRIPT>
</head>
<body>


<%@ include file="../top.jsp"%>  

 <center>
 <!--
 <table width="60%"> 
	 <tr>
		 <td width="100%">
	 --> 
	 <html:form action="/userregister"  method="post" onsubmit="return validateForm(this);">
	   <html:hidden property="id" />
	   <html:hidden property="action"/>
	   <html:hidden property="actionUpdateData"/>
	   
	   
	   
	   <table width="50%" border="1" class="signup"  align="center">

	<tr> 
	<td colspan="2" align="center">
		   <font size="4" color="#660099">Please Enter the Following Details</font><br>
		  </td>
		  </tr>
			
		
		   <!--
		   <tr>
			  <td align="right" width="50%"><b>Id</b></td> 
			  <td width="50%" align="left">
				 <html:text property="id" size="30" maxlength="120"/>
			  </td>
		 </tr> 
		 -->
		  <tr><td colspan="2" align="center"><font color="red"><html:errors/></font>
               &nbsp;</td></tr>
		 <tr>
		  <td align="right" width="50%"><b>User Id<font color="#FF0000">*</font></b></td>
		  <td align="left" width="50%">
			 <html:text property="userid" size="30" maxlength="120"/>
		  </td>
	 </tr>
	  <tr>
		  <td align="right"><b>Password<font color="#FF0000">*</font></b></td>
		  <td align="left">
			 <html:password property="password" size="30" maxlength="120"/>
		  </td>
	 </tr>

	<tr>
		  <td align="right"><b>Email</b></td>
		  <td align="left">
			 <html:text property="email" size="30" maxlength="120"/>
		  </td>
	 </tr>

	  <tr>
		  <td align="right"><b>Address</b></td>
		  <td align="left">
			 <html:text property="address" size="30" maxlength="120"/>
		  </td>
	 </tr>
	  <tr>
		  <td align="right"><b>Phone No.<b></td>
		  <td align="left">
			 <html:text property="phno" size="30" maxlength="120"/>
		  </td>
	 </tr>
	 <tr><td colspan="2">&nbsp;</td></tr>
	   <tr>
		  <td align="center" colspan="2">
			  <html:submit>Save</html:submit>
								
		  </td>
	 </tr>
	 </table>
</html:form>
   <!--
		 </td>
	 </tr>
 </table>
</center>
-->
</body>
</html:html>


 

Above file should be saved in the project\pages\user directory of web application.

Struts Registration Form

Registration form of the application which is associated with the ActionMapping "/userregister", which is action mapping used for registering the user. Here is code of Registration Form:

package roseindia.web.struts.form;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.*;

public class UserRegisterForm extends ActionForm{


     private String action="add";
     private String actionUpdateData;
    
      private Integer id;
    
      private String userid;
      private String password;
     
      private String email;
      private String address;
      private String phno;

   
      

      public void reset(ActionMapping mapping,HttpServletRequest request){
        
        this.id = null;
        this.userid=null;
        this.password=null;
        this.email=null;
        this.address=null;
        this.phno=null;
       
        this.action="add";
        this.actionUpdateData="";

      }


        public ActionErrors validate

        ActionMapping mapping, HttpServletRequest request ) {
        ActionErrors errors = new ActionErrors();
        
        return errors;
    }


    public String getAction() {
      return action;
    }


    public void setAction(String action) {
      this.action = action;
    }


    public String getAddress() {
      return address;
    }


    public void setAddress(String address) {
      this.address = address;
    }


    public String getEmail() {
      return email;
    }


    public void setEmail(String email) {
      this.email = email;
    }


    public String getPassword() {
      return password;
    }


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


    public String getPhno() {
      return phno;
    }

  
    
    public void setPhno(String phno) {
      this.phno = phno;
    }


    public String getUserid() {
      return userid;
    }


    public void setUserid(String userid) {
      this.userid = userid;
    }

    public String getActionUpdateData() {
      return actionUpdateData;
    }

    public void setActionUpdateData(String actionUpdateData) {
      this.actionUpdateData = actionUpdateData;
    }

    public Integer getId() {
      return id;
    }

    public void setId(Integer id) {
      this.id = id;
    
  
  
  
  
}

Above code UserRegistrationForm.java should be present in the project\WEB-INF\src\java\roseindia\web\struts\form directory of the project.

Success JSP Page

Success page confirms the successful completion of user registration. Here is the code of the success jsp page (registersuccess.jsp): 

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:html locale="true">

<head>

<title></title>
<html:base/>
</head>
<body>
<%@ include file="../top.jsp"%> 
<center>

<p><b>You are register successfuly !</b></p>
</center>
</body>
</html:html>

Above jsp page (registersuccess.jsp) should be saved into project\pages\user directory.

In this section we have developed JSP file and Struts action form for our application.

                         

» View all related tutorials
Related Tags: java c hibernate web error learning com configuration spring ide class j2ee frameworks jdbc data development ui ssis process framework

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

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

I download the code and try to run I was not able to register user using the above code. It doesn't throw any errors when I click the save button. I created users manually in the database and was able to login. Looks like registration has some issues. But I cant figure out the issue. It will be a great help if some could help me on this.

Thanks
Prasad

Posted by Prasad on Thursday, 11.13.08 @ 18:33pm | #81651

Communication Tube - Its a free web messenger chat client for the popular im: msn,Google Talk (GTalk),ICQ,irc. Communication Tube is compatible with all popular browsers.

Posted by webmessenger on Wednesday, 02.6.08 @ 05:38am | #47349

Luckly i got this code, but one thing i cont understand. where the user registration data's are storing

Posted by G.Viswanathan on Thursday, 01.17.08 @ 09:22am | #45403

What is the error "Cant create bean with dataSource" .... i met during my application running?
And when we extends the fields of the class login,for ex. group, position,... there are errors, about this following: no getter for method of property... group,position,..?
Please explain me why?. Do this error come from the My eclipse configuration?

Posted by TruongLQ on Monday, 12.24.07 @ 16:44pm | #43586


This example works fine . Thanks.

But my question is :

" What will happen if i Change property name in userRegister.jsp page "

then its not work properly .

Posted by Rajib Pal on Monday, 06.4.07 @ 16:49pm | #18178

To validate email format, I've had luck with the following regular expression:

/^\w+\@{1}\w+\.{1}\w+$/;

Posted by Frank on Tuesday, 04.3.07 @ 21:56pm | #13294

HI friends iam beginer to Structs. I need a
small structs application which consists of login page and registeration page(like
online
> student registration)using tomcat servler.
also i need how to set the classpath and run the application. plese can anyone help me for this application.it is urgent, plese help me.

>
> Regards,
> sreedhar murthy
> sreedhar_murthy99@yahoo.com

Posted by Sreedhar Murthy on Thursday, 03.29.07 @ 18:37pm | #12926

i wana a cod for login and registration form examples that may help me to develop my mail server, so plz kindly send me the required information.

Posted by riaz ahmad on Wednesday, 11.29.06 @ 12:40pm | #196

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
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.