Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create Captcha in Struts Registration JSP.

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to create Captcha in JSP(Register.jsp). I'm using struts-2. I downloaded JCaptcha.jar. But I don't know how to implement/display captcha in my JSP page. Please Help me.

Thanks:
Ramakrishna K.C
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They have a very simple tutorial here https://jcaptcha.atlassian.net/wiki/display/general/5+minutes+application+integration+tutorial
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its implementation in Servlets. I want in JSP like using struts. Like,

register.jsp

 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:Its implementation in Servlets. I want in JSP like using struts.


Did you read the part where it shows how the HTML img element is used to generate the captcha image?
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jaikiran Pai Sorry. I dint get that code.
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What problem you are facing exactly.Have you even tried that?

In your JSP will have to invoke your captcha servlet as image source something like below :



and will have to map corresponding servlet in your deployment descriptor(web.xml) something like below :



check the url pattern in servlet-mapping tag. it should match with src attribute of your img tag.

 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm telling, I don't want to use servlet. I'll not create sevlet class itself. Then Why should I map in web.xml like as you suggested. I already told



Its implementation in Servlets. I want in JSP like using struts.



Now I created one dynamic web project and add necessary struts-2 jars to lib(ALSO JCAPTCHA JAR) and In my web.xml I just added filter and filter-mapping. Now I've create JSP for registration which contains captcha as well. How will you do this? I given my JSP code also. Only these things I've in my project now.

Thanks:
Ramakrishna K.C
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:I'm telling, I don't want to use servlet. I'll not create sevlet class itself. Then Why should I map in web.xml like as you suggested. I already told

Its implementation in Servlets. I want in JSP like using struts.


JSP is meant to render the view and captcha image generation requires some server side entity like Servlet which sends you back the dynamic generated image. Why don't you want to use a Servlet? If your reason is that you are using Struts, then you can still use Servlets or at the very least you can use a Action class in Struts to do what that captcha servlet does. I don't remember much about Struts, but I think that should be possible.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got that. There is some logic should be there in server side to generate dynamic captcha.

Okay I'll try that.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Googling for "struts captcha" finds many example implementations. It's probably easier to start with one of those than trying to roll your own.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ulf Dittmer

Googling for "struts captcha" finds many example implementations.



I think, I did that. But, all examples have servlets not from Struts.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you tell us why you have such a dislike for Servlets?
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.. I love servlets. Not like that. But, I'm using struts, i dint know I can use both servlets and struts-2 together. in web.xml i've to do filter and filtermapping. Also servlets?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:i dint know I can use both servlets and struts-2 together.


You can

Ramakrishna Udupa wrote:
in web.xml i've to do filter and filtermapping. Also servlets?



Yes, you do it the same way like you would do for any servlet in a web application which doesn't use Struts.
 
Shiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic