Google reCaptcha不返回任何响应

时间:2019-03-27 14:42:47

标签: java recaptcha wildfly-10 jsf-1.2

我正在将google reCaptcha添加到登录页面。使用WyldFly 10上运行的JavaServer Faces Forms和JSF 1.2.Web应用程序中的j_security_check实施的登录表单提交。按预期,该页面上会出现Captcha面板。但是它不会对doLoginAction()方法返回任何响应。

我的login.xhtml中的表格:

<form method="POST" action="j_security_check" name="loginForm" autocomplete="off" id="loginForm" onsubmit="return checkBeforeSubmit();">
            <div id="boxtop"></div>
            <div id="boxmid">
                <div class="section">
                    <span><h:outputText id="usernameLabel" value="#{msg['page.login.username']}"/></span>
                    <input type="text" id="j_username" name="j_username" maxlength="60" autocomplete="off" 
                           onfocus="this.value = '';" onblur="if (this.value == '') {
                                       this.value = '#{msg['page.login.label']}';
                                   }" 
                           value="#{msg['page.login.label']}" />
                </div>  
                <div class="section">
                    <span><h:outputText id="passwordLabel" value="#{msg['page.login.password']}"/></span>
                    <input type="text" style="display:none;" />
                    <input type="password" id="j_password" name="j_password" maxlength="20" autocomplete="off"
                           onfocus="this.value = '';" onblur="if (this.value == '') {
                                       this.value = '#{msg['page.login.password.label']}';}"
                           value="#{msg['page.login.password.label']}" />
                </div>               
                <div class="g-recaptcha" data-sitekey="my-site-key"></div>                          
            <div class="text" style="float: right;">
                <input type="submit" value="Zaloguj" name="login" class="submit"  onclick="#{LoginBean.doLoginAction()}"/>
            </div>
        </form>

我的loginLayout.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>
        <link rel="shortcut icon" href="${request.contextPath}/img/icons/favicon.ico" id="favicon" type="image/x-icon"/>
        <title>jLeo</title>
        <meta name="description" content="" />
        <meta name="keywords" content="" />

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="refresh"
              content="${session.maxInactiveInterval};url=${request.contextPath}/sessionTimeout.xhtml"/>
        <a4j:loadStyle src="resource:///pl/com/adh/jleo/skin/#{LoginBean.skin}/css/default.css"/>
        <link href="${request.contextPath}/css/login/style.css" rel="stylesheet"  type="text/css" title="style" media="screen" />
        <script src="https://www.google.com/recaptcha/api.js"></script>
    </head>
    <body>       
    </body>
    <script src="${request.contextPath}/js/allLogin.js" type="text/javascript"></script>
</html>

我在LoginBean中的doLoginAction()方法:

 public String doLoginAction() {
         try {
        //here must be some response instead of null
        String gRecaptchaResponse = FacesContext.getCurrentInstance().
        getExternalContext().getRequestParameterMap().get("g-recaptcha-response");
        boolean verify = VerifyRecaptcha.verify(gRecaptchaResponse);
        if(verify){
             return "Success";
        }else{
             FacesContext context = FacesContext.getCurrentInstance();
             context.addMessage( null, new FacesMessage( "Select Captcha") );
             return null;
          }
         } catch (Exception e) {
             System.out.println(e);
         }
        return null;
     }    

在调试过程中,我对gRecaptchaResponse的响应为空,而不是响应。

0 个答案:

没有答案