Developing Forgot Password Form

An example that Developing a Forgot Password Form

Developing Forgot Password Form

Developing Forgot Password Form

     

In this section we will develop Forgot Password Form code for our application.

Developing Forgot Password Form

 

The forgot password form will be used, when user forgot their password. This form will get the user name and password from the user and forwarded it to the forgot password action, the forgot password action is responsible for forwarding user login name and password to the user. This form will take the user name and password and forgot password action action will compare the form value with the registered value from the database. The form should be developed in such a manner that it can take valid data from the user, therefore form validation must be implemented correctly.

As you know struts framework have there own set of tag libraries for developing a JSP file. Therefore will user the struts specific tag libraries

 

Please consider the steps for developing forgot password form
At first import the tag libraries  which will be used during writing a JSP page as,

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

Set the page title and import the CSS style sheet in your page

<head>
<title><bean:message key="welcome.title"/></title>
<LINK rel="stylesheet" type="text/css" name="anyname" href="<html:rewrite page='/css/style.css'/>">
</head>

Make a form using Struts tag

<html:form action="/userforgetpassword" method="post">
</html:form>

Make two text fields for, one for user name and other for email address, remember that the properties values must be same as you have typed in its bean class

<td align="right">User Name:</td> 
<td align="left"><html:text property="username" size="30" maxlength="30"/></td>
<td align="right">Email:</td> <td><html:text property="email" size="30" maxlength="30"/></td>
<td align="center" colspan="2"><html:submit>Send Me My Username and Password</html:submit></td>

The form validation will be done in the bean class (server side) in the validate method and if any invalid field is found the bean will return an action error

 

The complete code of fogot passowrd JSP is given below

forgotPassword.jsp

<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<html:html locale="true">
     <head>
	<title><bean:message key="welcome.title" /></title>
        <LINK rel="stylesheet" type="text/css" name="anyname"
         href="<html:rewrite page='/css/style.css'/>">
      </head>
   <html:base />
<body>
<%@ include file="../top.jsp"%>
<center>
<table width="40%">
   <tr>
	<td><html:form action="/userforgetpassword" method="post">
	<table border="0" cellspacing="2" cellpadding="1" width="100%"
		class="signup">
   <tr>
	<td align="center" colspan="2"><font size="5">Access
	Your Username and password</font></td>
   </tr>
   <tr>
	<td align="center" colspan="2"><font color="red"><html:errors /></font></td>
   </tr>
   <tr>
	<td colspan="2">
	<p>&nbsp</p>
	</td>
   </tr>
   <tr>
	<td colspan="2">
	<li>Enter your user name as registered</li>
	</td>
	</tr>
  <tr align="center">

	<td align="right">User Name:</td>
	<td align="left"><html:text property="username" size="30"
	maxlength="30" /></td>
  </tr>
  <tr>
	<td colspan="2">
 	<p>&nbsp;</p>
	</td>
  </tr>
  <tr>
  	<td colspan="2">
	<li>OR If you do not remember your username, then enter your
	e-mail address as entered in your resume:</li>
	</td>
  </tr>
  <tr>
	<td align="right">Email:</td>
	<td><html:text property="email" size="30" maxlength="30" /></td>
  </tr>
  <tr>
	<td colspan="2">
	<p>&nbsp;</p>
	</td>
  </tr>
  <tr>
	<td align="center" colspan="2"><html:submit>Send Me My Username and Password</html:submit></td>
  </tr>
<!-- <tr><td colspan="2"><p>&nbsp;</p></td></tr> -->
</table>
</html:form></td>
</tr>
</table>

</center>
</body>
</html:html>

View Of the form