Hello,

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

Register.jsp:

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

you can controll cookie with javascript.
http://www.w3schools.com/js/js_cookies.asp
you can find how to use cookie here.

simple solution is here
reg.jsp

<% 
    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");
%>
<script>
    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;
    }else{
        //return to index page
        alert(">Already registered!!");
        location.href = "index.jsp";
    }
</script>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.