Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HtmlUnit登录表单,javascript问题_Java_Javascript_Forms_Login_Htmlunit - Fatal编程技术网

HtmlUnit登录表单,javascript问题

HtmlUnit登录表单,javascript问题,java,javascript,forms,login,htmlunit,Java,Javascript,Forms,Login,Htmlunit,您好,我正在尝试使用htmlunit登录到服务器。当我禁用htmlunit的javascript支持时,我的程序会成功发布登录信息,但会将我重定向到另一个页面,该页面会显示“因为你没有使用javascript,所以必须按一下continue”。即使在普通浏览器中,自动单击此“继续”按钮也会生成404页面,因此这不是一个选项 因此,我需要设置javascript以执行身份验证。有人能帮我吗?下面是我的代码、抛出错误的堆栈跟踪以及我正在使用的html源代码。提前谢谢 WebClient wc

您好,我正在尝试使用
htmlunit
登录到服务器。当我禁用
htmlunit的
javascript支持时,我的程序会成功发布登录信息,但会将我重定向到另一个页面,该页面会显示“因为你没有使用javascript,所以必须按一下continue”。即使在普通浏览器中,自动单击此“继续”按钮也会生成404页面,因此这不是一个选项

因此,我需要设置javascript以执行身份验证。有人能帮我吗?下面是我的代码、抛出错误的堆栈跟踪以及我正在使用的html源代码。提前谢谢

    WebClient wc = new WebClient(BrowserVersion.FIREFOX_3_6);
    wc.getCookieManager().setCookiesEnabled(true);
    wc.setJavaScriptEnabled(true);

    HtmlPage page0 = wc.getPage("https://my.usc.edu/wp/shiblogin.do?r=/wp/student/searchForm.do");
    HtmlPage page1 = wc.getPage("https://shibboleth.usc.edu/idp/Authn/UserPassword");

    HtmlForm loginForm = page1.getForms().get(0);

    //HtmlSubmitInput button = loginForm.getInputByValue("Login");
    HtmlTextInput userField = loginForm.getInputByName("j_username");
    HtmlPasswordInput passwordField = loginForm.getInputByName("j_password");

    userField.setValueAttribute("username");
    passwordField.setValueAttribute("password");

    HtmlPage page2 = (HtmlPage) loginForm.getInputByValue("Login").click();

    String htmlBody = page2.getWebResponse().getContentAsString();

    System.out.println(page2.asText());
    System.out.println(htmlBody);



USCnet登录
USC NetID:
密码:

是什么javascript阻止表单在启用javascript支持的情况下成功发布?html.onsubmit=“if(this.getAttribute('submited'))的第一行返回false;this.setAttribute('submited','true');document.getElementById('submit')。disabled=true;”
Caused by: com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 >/wp/student/searchForm.do/index.html for >https://my.usc.edu/wp/student/searchForm.do/index.html
>   at >com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebCli>ent.java:543)
>   at com.gargoylesoftware.htmlunit.WebClient.download(WebClient.java:2228)
>   at >com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFormElement.submit(HTMLFormElement.jav>a:310)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>   at >sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>   at java.lang.reflect.Method.invoke(Method.java:597)
>   at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:137)
>   ... 34 more
>== CALLING JAVASCRIPT ==
>function () {
>   [native code, arity=0]
>}

>======= EXCEPTION END ========
<form id="loginform" action="/idp/Authn/UserPassword" method="post" onsubmit="if (this.getAttribute('submitted')) return false; this.setAttribute('submitted','true'); document.getElementById('submit').disabled=true;" >

                <fieldset>
                    <legend>USCnet Login</legend>
                    <table id="login">
                        <tr>
                            <th><label for="j_username">USC NetID:</label></th>
                            <td><input id="j_username" name="j_username" type="text" maxlength="12" value="" /></td>
                        </tr>
                        <tr>
                            <th><label for="j_password">Password:</label></th>
                            <td><input id="j_password" name="j_password" type="password" /></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input id="submit" type="submit" value="Login" /></td>
                        </tr>