<!-- JSP Code -->

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>

<portlet:defineObjects />

<portlet:resourceURL var="captchaURL"/>

<form action="<portlet:actionURL/>" method="post">
	<liferay-ui:captcha url="<%= captchaURL %>"/>
	<input type="submit"></input>
</form>



/* GenericPortlet extended controller class */
@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException {
    try {
    	com.liferay.portal.kernel.captcha.CaptchaUtil.serveImage(resourceRequest, resourceResponse);
    } catch (Exception e) {	e.printStackTrace(); }
    }

@Override
public synchronized void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
	String eText = ParamUtil.getString(request, "captchaText");
	String cText = getCaptchaText( request );

	if ( eText.equals( cText ) ) {
		/* Captcha OK */
		} else {
		/* Captcha KO */
        }
    }

private String getCaptchaText( ActionRequest request ) {
    PortletSession session = request.getPortletSession();

    Enumeration<String> atNames = session.getAttributeNames();
    while (atNames.hasMoreElements()) {
        String name = atNames.nextElement();
        if (name.contains("CAPTCHA_TEXT")) {
			String cText=(String) session.getAttribute(name);

			return cText;
        	}
    	}

    return "";
    }