I am new to JSP and I have to create a registration form, so when the user fills out all the information and clicks submit, the information should be stored in cookies. I cannot use database to store user information. Also after the user registers, he/she has to login and I have to validate the username and password with the user information stored in cookies. I have searched online for solution but couldnt find any!, Please Help


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>New User Registration</title>
    <form method="post" action="reg.jsp">
            <table border="1" width="30%" cellpadding="5">
                        <th colspan="2">Enter Information Here</th>
                        <td>First Name</td>
                        <td><input type="text" name="fname" value="" /></td>
                        <td>Last Name</td>
                        <td><input type="text" name="lname" value="" /></td>
                        <td><input type="text" name="email" value="" /></td>
                        <td>User Name</td>
                        <td><input type="text" name="uname" value="" /></td>
                        <td><input type="password" name="pass" value="" /></td>
                        <td><input type="submit" value="Submit" /></td>
                        <td><input type="reset" value="Reset" /></td>
                        <td colspan="2">Already registered!! <a href="index.jsp">Login Here</a></td>

you can controll cookie with javascript.
you can find how to use cookie here.

simple solution is here

    String fname = request.getParameter("fname");
    String lname = request.getParameter("lname");
    String email = request.getParameter("email");
    String uname = request.getParameter("uname");
    String pass = request.getParameter("pass");
    var cookie_name = "login_cookie_"+"<%=email%>";
    var cookie_value = "<%=fname%>" + "_" + "<%=lname%>" + ... + "<%=pass%>";//connect each value with "_"

    //get cookie
    var current_cookie = document.cookie;

    //check cookie
    if(current_cookie.indexOf(cookie_name + "=") == -1){
        //set cookie
        document.cookie = cookie_name + "=" + cookie_value;
        //return to index page
        alert(">Already registered!!");
        location.href = "index.jsp";

ps) if you use jquery, then use jquery.cookie plugin. it makes easy to use cookie.