how to make security code in jsp?

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

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.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

I'm working in Excel to extract content of a table from a web page and populate Excel sheet cells with it. I'm trying to extract data from a table that gets loaded to a web page after show results method gets called. I have an error that says "Run-time error ...