Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet registration form
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sarika sharma
registration form
1 Answer(s)      4 years ago
Posted in : JSP-Servlet


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


Advertisement
View Answers

March 16, 2011 at 4:32 PM


<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:
&lt;%@ page language="java"
    import="java.util.<em>,saar.etisalat.</em>,java.sql.*,saar.etisalat.Conn"
    pageEncoding="ISO-8859-1"%>
&lt;%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    String name=request.getParameter("name");
%></p>

<p>&lt;%!
    Connection connection = null;
    PreparedStatement preparedStatement = null,preparedStatement1 =null; 
    ResultSet resultSet = null,resultSet1=null;%></p>

<pre class="prettyprint">&lt;%  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">    &lt;p&gt;&lt;table style="margin-top : 100px" align="center" border=0&gt;
        &lt;form name="f1" action="CreateUser" method="post" onsubmit="return valid();"&gt;
          &lt;%if(session.getAttribute("name")!=null)
</code></pre>

<p>{%><td colspan=4>
  &lt;B style="color:teal">User Successfully Created</B></td> &lt;% 
      session.removeAttribute("name");
} %> <br />
&lt;%if(session.getAttribute("resultSetuser")!=null)
{%><td colspan=4>
   &lt;B style="color:red">username already exists select different name</B></td>
        &lt;%   session.removeAttribute("resultSetuser");
} %> <br />
 <div>
   <table border="0" style="width: 96%; border-collapse: collapse"
                    cellpadding="0" align="center">
                    <tr>
                        <td colspan="3">
                            &nbsp;
                        </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">                              &lt;tr&gt;
                    &lt;td class="PageBodyL"&gt;&lt;/td&gt;

                    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
                    &lt;p&gt;&amp;nbsp;&lt;/p&gt;

                    &lt;/td&gt;

                &lt;/tr&gt;
                                    &lt;tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;table border=0 align="center"&gt;
                                         &lt;tr&gt;&lt;td align="left" colspan=2&gt;User Name&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input type="text" size=30 class="textbox" name="name" /&gt;&lt;/td&gt;
            &lt;tr&gt;&lt;td align="left" colspan=2&gt;Full Name&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
                &lt;td align="left"&gt;&lt;input type="text" size=30 class="textbox" name="fullname" /&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;tr&gt;&lt;td align="left" colspan=2&gt;Password&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
                &lt;td align="left"&gt;&lt;input type="password" size=30 class="textbox" name="pass" /&gt;&lt;/td&gt;&lt;tr&gt;
            &lt;tr&gt;&lt;td colspan=2 align="left"&gt;Confirm Password&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
                &lt;td align="left"&gt;&lt;input type="password" size=30 class="textbox" name="cpass" /&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;tr&gt;&lt;td align="left" colspan=2&gt;Role&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
                &lt;td align="left"&gt;&lt;select name="sel" class="dropbox"&gt;
                    &lt;option&gt; -Select- &lt;/option&gt;
                    &lt;%
                        while (resultSet.next()) {
                                String roles = resultSet.getString("role_name");
                                String roleid = resultSet.getString("role_id");
                    %&gt;
                    &lt;option value=&lt;%=roleid%&gt; size=30&gt;&lt;%=roles%&gt;&lt;/option&gt;
                    &lt;%
                        }
                        } catch (SQLException se) {
                            se.printStackTrace();
                        } finally {
                            Conn.closeConnection(resultSet, preparedStatement, connection);
                        }
                    %&gt;
                &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
                                    &lt;/tr&gt;
                        &lt;td&gt;&lt;/td&gt;

                            &lt;table border=0 align="center"&gt;
                                &lt;tr&gt;
                                    &lt;td&gt;
                                        &lt;input type=submit class="butn" value=Save /&gt;

                                        &lt;input type=reset class="butn" value=Reset /&gt;
                                    &lt;/td&gt;
                                &lt;/tr&gt;
                                &lt;/td&gt;
                                &lt;/tr&gt;
                            &lt;/table&gt;
                    &lt;/td&gt;
                    &lt;td class="PageBodyR"&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td class="PageBodyL"&gt;&lt;/td&gt;
                    &lt;td class="PageBodyM"&gt;
                    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
                    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
                    &lt;/td&gt;
                    &lt;td class="PageBodyR"&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td class="PageBottomL"&gt;&lt;/td&gt;
                    &lt;td class="PageBottomM"&gt;
                        ┬ęSaaR. All rights reserved
                    &lt;/td&gt;
                    &lt;td class="PageBottomR"&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;&lt;/table&gt;

        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
</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 &amp;#95</p>


Related Tutorials/Questions & Answers:
Registration Form
Registration Form  Hi Friends I am Working on a small project.I have to create a Registration page using MVC pattern where i have to insert data username,password,date of birth,Mobile number number into database. How to insert
registration form
registration form  Hii.. I have to design one registration page in java that looks like REGISTER USERNAME (here i have to check whether...="center" border=0&gt; &lt;form name="f1" action="CreateUser
Advertisements
to creating a registration form
to creating a registration form  how to create a registration form
Registration Form in HTML
Registration Form in HTML  User Registration Form in HTML - i wanted to design a user registration form in HTML. So, Can anyone please guide me or give me a peace of code to design a user registration form in HTML. Thanks
popup registration form
popup registration form  hi i want a code for popup registration form.when user click a button popup form will appear.thanks.
Login form and registration
Login form and registration  I need a complete code for ligin and new user registration form and validation
form registration on JavaScript
form registration on JavaScript   i want form of registration on JavaScript > < check the name is string or number & if the name number output error >> and the same of email and birthday and country >> <
JSP code for registration form
JSP code for registration form  Haiiii can u please tell me how to encrypt password field in registration form and to compare both password and confirm password fields using jsp
AJAX REGISTRATION FORM
AJAX REGISTRATION FORM  I have implemented user name, check and state selection using ajax, in the html registration form. I am loading two XML... either username or state. How to implement both in same registration form could any
to create registration form
to create registration form  hello friends,im student and i want to do an assignment on to create an registration form with 20 input fields by using...://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
user Registration form using bean
user Registration form using bean   In this code,password and confirm password does n't matches.Every time an error occured if i entered same string for both.Please help to sort my problem
creating web page for form registration
creating web page for form registration  I am creating web page for form registration to my department ..I have to Reprint the Application Form (i.e Download the PDf File from the Database ) , when the user gives the Application
how to create a user registration form in php
how to create a user registration form in php  how to create a user registration form in php
registration form using oop concept
registration form using oop concept  I would like to write a program student registration form at kindergartens and display the information... the output?   Registration Form: import javax.swing.*; import java.awt.
How do I compile the registration form?
How do I compile the registration form?  How do I compile the registration form as stated at the bottom of the following page (URL is below). Do I...://www.roseindia.net/struts/hibernate-spring/user-registration-action.shtml
web page for form registration to my department
web page for form registration to my department  I am creating web page for form registration to my department ..I have to Reprint the Application Form (i.e Download the PDf File from the Database ) , when the user gives
Developing User Registration Form
Developing User Registration Form   ... necessary to develop the User Registration Form for our Struts, Hibernate and Spring... how to develop the User Registration Form and related JSP files. This User
database spring registration form
database spring registration form We are going to discuss about  database spring registration form. We have created simple spring registration form... registration form. We have used controller and we are using database
HTML Code for registration form
HTML Code for registration form Here is an example of Registration form using...;Registration form</h2> <form action="Welcome.html" method=".... The name in front of Text Field is called "Label". At the end of the registration
User Registration Form Using JSP(JspBeans)
User Registration Form Using JSP(JspBeans)  ... of user registration form using jsp. One of the basic programming tactics... a simple registration form (register.html):       <
html code for student registration form
html code for student registration form Here is an example of html code for student registration form. In this example, we have displayed many text fields... in student registration form. If you will not enter value in text field than an error
HTML(Registration form) to Jsp to stored into MS ACCESS database
HTML(Registration form) to Jsp to stored into MS ACCESS database  i am sending one html file that contain 18 fields these are stored in ms-access database by using jsp code.i want to urgent jsp code. please urgent sir. thank
userregistration code -- http://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
userregistration code -- http://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml  While running this application on netbeans7.0 , i am getting the following error: message /userregister/ description The requested
How to Create Login/ Registration Form using PHP and MYSQL
How to Create Login/ Registration Form using PHP and MYSQL  Hi, I am learning PHP. I have some dilemma how to create a Login Form and make connectivity with HTML page using PHP and MYSQL. Is there any body can guide me
How to Create Student Registration Form with HTML Code?
How to Create Student Registration Form with HTML Code? At present, the concept of online student registration form has emerged as a great relief... will learn to create a student registration form using html code in easy steps
Develop user registration form
User Registration Form in JSP     ... registration form which will insert  the entered  data into the database... will be inserted  into the database. Firstly the registration form
login and registration form using servlet and authentication through mysql
login and registration form using servlet and authentication through mysql  i made a simple login and rgistration form using servlet... help here is my code...plz chk the web.xml file also index.jsp(login form) <
How to insert data into databse by JSP form registration page in netbeans
How to insert data into databse by JSP form registration page in netbeans  ... a student. I have been given a task to create registration page with username & password, & after submitting this form it automatically stores data
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE.... 1)register.jsp <html> <form method="post" action="insert.jsp"> <
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE.... 1)register.jsp <html> <form method="post" action="insert.jsp"> <
User Registration Form Using JSP(JspBeans) after that how i can insert in database
User Registration Form Using JSP(JspBeans) after that how i can insert in database   User Registration Form Using JSP(JspBeans) after that how i can insert in database
Advertisements
 

 

 

DMCA.com