i need idea how to make security code in jsp..
for example:
when we register to any website, mostly we need to fill
the security code that appear at the registration form page.
so how can,I as a developer to do that security code?
this is the example of security code:
how can i call that image to my form?
and it pick randomly from the database

Attachments v2rypa.gif 16.98 KB
7 Years
Discussion Span
Last Post by muhdadeel

You have to write appropriate code in your registration jsp.

1. Generate a random text or number.
2. Push (save) it to cookies or session.
3. Draw an image into buffer and save it. - Graphics - java.awt
4. Use img tag to set src attribute with path of newly created image.
5. Add a text tag (say spamtext) near to the image.

After form is filled up and user hit submit then,

1. Read the value of spamtext and compare it with the value which
was pushed (saved) into cookies or session.
I hope, you will get it.


Hi ,

Its really easy to do using JSP,just you need to have some basics of JavaScript , Jsp and html.

<%@ page import="java.util.*" %>

<script type="text/javascript">

    function check_number()
        var r_number = document.getElementById("number").value;
        var u_number =document.getElementById("userI").value;

            alert("no pal");



Random Generator = new Random();
int r = Generator.nextInt(10000);


<input id="number" type="hidden" value="<%=r%>" />


<b>Enter Above Number:</b><input type="text"  id="userI" /><input type="button" value="Check" onclick="check_number();" />

Muhammad Khokhar
Software Engineer
Sun Microsystem,UK

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.