Sunday, August 4, 2013

Implementing Captcha for J2EE application


Implementing Captcha for J2EE application

Here I am going to explain how you can add captcha to J2EE based web application.

List of jar files requored:
1.            jcaptcha-2.0-alpha-1-SNAPSHOT.jar
2.            jcaptcha-api-1.0.jar
3.            jcaptcha-integration-simple-servlet-2.0-alpha-1-SNAPSHOT.jar
As you going to have captcha for you application you have to make below entry in you web.xml file.

Servlet definition for Captcha

<servlet>
        <servlet-name>jcaptcha</servlet-name>
        <servlet-class>com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet</servlet-class>
  </servlet>

Servlet mapping for captcha

<servlet-mapping>
        <servlet-name>jcaptcha</servlet-name>
        <url-pattern>/jcaptcha.jpg</url-pattern>
  </servlet-mapping>

 

Show captcha Image

<p:graphicImage id="captchaImage" value="jcaptcha.jpg" />

 

Taking input from user

<p:inputText styleClass="textfield"  value="#{customerBean.captchaText}" required="true" requiredMessage="Enter security code"></p:inputText>

 

Validating Input with captcha text

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
                        boolean isCaptchaValidate = SimpleImageCaptchaServlet.validateResponse(request,customerBean.getCaptchaText());
                       


Now you can enjoy captcha on you applicaiton

10 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I appreciate you sharing this article. Really thank you! Much obliged.
    This is one awesome blog article. Much thanks again.


    sap online training
    software online training
    sap sd online training
    hadoop online training
    sap-crm-online-training

    ReplyDelete
  3. I really enjoy the blog.Much thanks again. Really Great.
    Very informative article post. Really looking forward to read more. Will read on…


    oracle online training
    sap fico online training
    dotnet online training
    qa-qtp-software-testing-training-tutorial

    ReplyDelete
  4. simple and superb.... really good article

    ReplyDelete
  5. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic. Amazon Web Services Training in Chennai

    Amazon Web Services Training Institute in Chennai

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Amazing blog. It's very helpful to learn these things easily. Thank You so much. Keep supporting. 
     aws training in chennai aws course in chennai 

    ReplyDelete
  8. I believe there are many more pleasurable opportunities ahead for
    individuals that looked at your site.
    oracle course in chennai
    ASP Dot Net Training in Chennai
    C Sharp Training in Chennai

    ReplyDelete

Thanks for your valuable comment. You comment will go live soon.