Hii.. I have to design one registration page in java that looks like
REGISTER
USERNAME (here i have to check whether username already exists in database) EMAIL ADDRESS (here i have to check whether email address already exists in database) PASSWORD
WORD SUGGESTIONs (here i have to design captcha)
submit (while clicking on submit button i have to send verification mail to the user)
please tell me how could i design that. Please help me asap Thanks a lot
<p>CreateUser.java:
package saar.etisalat.dao;</p>
<p>import java.io.*;</p>
<p>import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;</p>
<p>import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;</p>
<p>import saar.etisalat.Conn;</p>
<p>public class CreateUser extends HttpServlet {</p>
<pre class="prettyprint">/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public CreateUser() {
super();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection connection = null;
PreparedStatement preparedStatement = null;
CallableStatement callableStatement = null;
ResultSet resultSet = null;
ResultSet resultSet1 = null;
connection = Conn.openConnection();
String userName = request.getParameter("name");
String fullName = request.getParameter("fullname");
String password = request.getParameter("pass");
String roleid = request.getParameter("sel");
HttpSession session = request.getSession();
String sessionUserName = (String) session.getAttribute("sessionUser");
String userId = null;
String query = null;
String dbusername = null;
try {
preparedStatement = connection
.prepareStatement("select user_name from user_details where user_name=?");
preparedStatement.setString(1, userName);
System.out.println(userName);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
dbusername = resultSet.getString("user_name");
System.out.println(dbusername);
}
if (dbusername == null) {
System.out.println("in if");
query = "{call user_create(?,?,?,?,?,?,0)}";
callableStatement = connection.prepareCall(query);
callableStatement.setString(1, userName);
callableStatement.setString(2, fullName);
callableStatement.setString(3, roleid);
callableStatement.setString(4, password);
callableStatement.setString(5, sessionUserName);
callableStatement.setString(6, sessionUserName);
resultSet1 = callableStatement.executeQuery();
session.setAttribute("name", userName);
if (session.getAttribute("name") != null) {
response.sendRedirect("CreateUser.jsp");
}
} else if (resultSet != null) {
System.out.println("in else");
session.setAttribute("resultSetuser", resultSet);
if (session.getAttribute("resultSetuser") != null) {
response.sendRedirect("CreateUser.jsp");
}
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
} finally {
Conn.closeConnection(resultSet, callableStatement, connection);
}
}
</code></pre>
<p>}</p>
<p>CreateUser.jsp:
<%@ page language="java"
import="java.util.<em>,saar.etisalat.</em>,java.sql.*,saar.etisalat.Conn"
pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
String name=request.getParameter("name");
%></p>
<p><%!
Connection connection = null;
PreparedStatement preparedStatement = null,preparedStatement1 =null;
ResultSet resultSet = null,resultSet1=null;%></p>
<pre class="prettyprint"><% connection=Conn.openConnection();
try{
preparedStatement = connection
.prepareStatement("select distinct role_name ,role_id from role order by role_name");
resultSet = preparedStatement.executeQuery();
</code></pre>
<p> %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Etisalat Login Page</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link href="styles/styles.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript">
function valid()
{</p>
<pre class="prettyprint">if (document.f1.name.value== "")
{
alert("fill the username");
f1.name.value="";
f1.name.focus();
return false;
}
if (document.f1.fullname.value== "")
</code></pre>
<p>{
alert("Enter fullname");
f1.fullname.focus();
return false;
}</p>
<p> if(document.f1.pass.value=="")
{
alert("fill the password field");
f1.pass.focus();
return false;
}
if(document.f1.pass.value!=document.f1.cpass.value)
{
alert("password didnt match");
f1.pass.focus();
return false;
}</p>
<p> if ( document.f1.sel.selectedIndex == 0 ) {
alert ( "Please select role" );
return false;
} </p>
<pre class="prettyprint">return true;
</code></pre>
<p>}</p>
<p>function focuson(){
document.f1.name.focus();
}</p>
<p> </script>
</head>
<body class="bodyColor" onload="focuson();"></p>
<pre class="prettyprint"> <p><table style="margin-top : 100px" align="center" border=0>
<form name="f1" action="CreateUser" method="post" onsubmit="return valid();">
<%if(session.getAttribute("name")!=null)
</code></pre>
<p>{%><td colspan=4>
<B style="color:teal">User Successfully Created</B></td> <%
session.removeAttribute("name");
} %> <br />
<%if(session.getAttribute("resultSetuser")!=null)
{%><td colspan=4>
<B style="color:red">username already exists select different name</B></td>
<% session.removeAttribute("resultSetuser");
} %> <br />
<div>
<table border="0" style="width: 96%; border-collapse: collapse"
cellpadding="0" align="center">
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td class="CC1L"></td>
<td class="CC1M">
CREATE USER
</td>
<td class="CC1R"></td>
</tr>
<tr>
<td class="PageBodyL"></td>
<td class="PageBodyM">
<table>
<tr>
<td>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr></p>
<pre class="prettyprint"> <tr>
<td class="PageBodyL"></td>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
</tr>
<tr><tr><td></td></tr><table border=0 align="center">
<tr><td align="left" colspan=2>User Name</td><td></td>
<td align="left"><input type="text" size=30 class="textbox" name="name" /></td>
<tr><td align="left" colspan=2>Full Name</td><td></td>
<td align="left"><input type="text" size=30 class="textbox" name="fullname" /></td></tr>
<tr><td align="left" colspan=2>Password</td><td></td>
<td align="left"><input type="password" size=30 class="textbox" name="pass" /></td><tr>
<tr><td colspan=2 align="left">Confirm Password</td><td></td>
<td align="left"><input type="password" size=30 class="textbox" name="cpass" /></td></tr>
<tr><td align="left" colspan=2>Role</td><td></td>
<td align="left"><select name="sel" class="dropbox">
<option> -Select- </option>
<%
while (resultSet.next()) {
String roles = resultSet.getString("role_name");
String roleid = resultSet.getString("role_id");
%>
<option value=<%=roleid%> size=30><%=roles%></option>
<%
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
Conn.closeConnection(resultSet, preparedStatement, connection);
}
%>
</select></td></tr>
</tr>
<td></td>
<table border=0 align="center">
<tr>
<td>
<input type=submit class="butn" value=Save />
<input type=reset class="butn" value=Reset />
</td>
</tr>
</td>
</tr>
</table>
</td>
<td class="PageBodyR"></td>
</tr>
<tr>
<td class="PageBodyL"></td>
<td class="PageBodyM">
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td class="PageBodyR"></td>
</tr>
<tr>
<td class="PageBottomL"></td>
<td class="PageBottomM">
©SaaR. All rights reserved
</td>
<td class="PageBottomR"></td>
</tr>
</table></table>
</div>
</form>
</body>
</code></pre>
<p></html></p>
<p>Here is the code for user already exists...Smilarly check it for the email._ in this is shown as &#95</p>