Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/05/2011, 02:44
mafyas
 
Fecha de Ingreso: febrero-2011
Mensajes: 11
Antigüedad: 13 años, 2 meses
Puntos: 0
Introduciendo un captcha

Hola, recientemente estoy introduciendo un captcha en un formulario y en vez de enviar los datos al servlet que valida el resto de campos, porque no solo tendria que tocar ese servlet al querer meter mi validacion nueva si no que tendria que cambiar cosas de muchos otros sitios
asique pense en en el form hacer una validacion cuando le se da a submit vuelves a la pagina comprobandolo, despues de la comprobacion quiero hacer que si esta correcto, envia la informacion al servlet para que haga su funcion pero no se como hacerlo
Código:
<%
    boolean problem = (request.getParameter("feedback.problem") != null);
    String email = request.getParameter("email");

    if (email == null || email.equals(""))
    {
        email = (String) request.getAttribute("authenticated.email");
    }

    if (email == null)
    {
        email = "";
    }

    String feedback = request.getParameter("feedback");
    if (feedback == null)
    {
        feedback = "";
    }

    String fromPage = request.getParameter("fromPage");
    if (fromPage == null)
    {
        fromPage = "";
    }


   String msg="";
String secHash ="";
String originalHash="";
String seccode = request.getParameter ("code");
System.out.println("Valor caja texto : "+seccode);
if(!(seccode == null || seccode.equals("null"))){
  originalHash=(String)session.getAttribute("captcha");
  System.out.println("Valor de captcha sesion : "+originalHash);
  secHash = seccode;

 if(originalHash.equals(secHash)){
 %>msg="<span style="color: green;">Correcto</span> ";<%
 }else{
 %>msg="<span style="color: red;">Error</span> ";<%
 }
}
%>

<dspace:layout titlekey="jsp.feedback.form.title">
    <%-- <h1>Feedback Form</h1> --%>
    <h1><fmt:message key="jsp.feedback.form.title"/></h1>

    <%-- <p>Thanks for taking the time to share your feedback about the
    DSpace system. Your comments are appreciated!</p> --%>
    <p><fmt:message key="jsp.feedback.form.text1"/></p>

<%
    if (problem)
    {
%>
        <%-- <p><strong>Please fill out all of the information below.</strong></p> --%>
        <p><strong><fmt:message key="jsp.feedback.form.text2"/></strong></p>
<%
    }
%>

    <form action="form.jsp" method="post">
        <center>
            <table>
                <tr>
                    <td class="submitFormLabel"><label for="temail"><fmt:message key="jsp.feedback.form.email"/></label></td>
                    <td><input type="text" name="email" id="temail" size="50" value="<%=StringEscapeUtils.escapeHtml(email)%>" /></td>
                </tr>
                <tr>
                    <td class="submitFormLabel"><label for="tfeedback"><fmt:message key="jsp.feedback.form.comment"/></label></td>
                    <td><textarea name="feedback" id="tfeedback" rows="6" cols="50"><%=StringEscapeUtils.escapeHtml(feedback)%></textarea><br><br>
                        
                    </td>
                    <td>
                        <img alt="imagenCaptcha" src="cap3.jsp" id="captcha">
                        <input name="code" size="20" type="text"/><%=msg%>
                        

                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                    <input type="submit" name="submit" value="<fmt:message key="jsp.feedback.form.send"/>" />
                    </td>
                </tr>
            </table>
        </center>
    </form>

</dspace:layout>