hai...
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

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
package.
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;

        if(r_number==u_number)
            alert("Good!");
        else
            alert("no pal");

    }


</script>
<%

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


%>


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


<br/>
<br/>
<h2><%=r%></h2>
<br/>

<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

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.