我在尝试通过htmlunit webclient访问页面时遇到此错误:
代码示例:
final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_11);
WebClientOptions webClientOptions = webClient.getOptions();
webClientOptions.setSSLClientCertificate(new URL("File:C:\\Cert.pfx"), "dubqf!$@", "PKCS12");
webClientOptions.setUseInsecureSSL(true);
webClientOptions.setSSLTrustStore(new URL("File:C:\\Program Files (x86)\\Java\\jdk1.7.0_01\\jre\\lib\\security\\cacerts"), "changeit", "jks");
webClientOptions.setThrowExceptionOnScriptError(false);
webClientOptions.setThrowExceptionOnFailingStatusCode(false);
webClientOptions.setActiveXNative(true);
final HtmlPage pg = webClient.getPage(u);
HtmlPasswordInput pass = (HtmlPasswordInput) pg.getElementById("PasswordTxt");
HtmlTextInput ac = (HtmlTextInput) pg.getElementById("AgentCode");
HtmlTextInput oc = (HtmlTextInput) pg.getElementById("OfficeCode");
HtmlTextInput ut = (HtmlTextInput) pg.getElementById("UserTxt");
ac.click(); ac.type("1058");
oc.click(); oc.type("07");
ut.click(); ut.type("gebrane");
pass.click(); pass.type("gebran.h2");
ScriptResult result = pg.executeJavaScript("__doPostBack('LogInLinkBut','')");
HtmlPage newPage = (HtmlPage) result.getNewPage();
附上例外:
java.lang.RuntimeException:调用jsConstructor的异常 at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:181) at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:391) at net.sourceforge.htmlunit.corejs.javascript.BaseFunction.construct(BaseFunction.java:394) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1591) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411) 在com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3286) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine $ 3.doRun(JavaScriptEngine.java:827) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine $ HtmlUnitContextAction.run(JavaScriptEngine.java:939) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:836) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:812) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:800) 在com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:910) 在com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:354) 在com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:415) 在com.gargoylesoftware.htmlunit.html.HtmlScript $ 3.execute(HtmlScript.java:271) 在com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:293) 在com.gargoylesoftware.htmlunit.html.HTMLParser $ HtmlUnitDOMBuilder.endElement(HTMLParser.java:799) 在org.apache.xerces.parsers.AbstractSAXParser.endElement(未知来源) 在com.gargoylesoftware.htmlunit.html.HTMLParser $ HtmlUnitDOMBuilder.endElement(HTMLParser.java:756) 在org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170) 在org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072) 在org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206) 在org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330) 在org.cyberneko.html.HTMLScanner $ ContentScanner.scanEndElement(HTMLScanner.java:3126) 在org.cyberneko.html.HTMLScanner $ ContentScanner.scan(HTMLScanner.java:2093) 在org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920) 在org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499) 在org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452) 在org.apache.xerces.parsers.XMLParser.parse(未知来源) 在com.gargoylesoftware.htmlunit.html.HTMLParser $ HtmlUnitDOMBuilder.parse(HTMLParser.java:1039) 在com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:252) 在com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:198) 在com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:271) 在com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:159) 在com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:478) 在com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2135) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:982) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access $ 500(JavaScriptEngine.java:103) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine $ HtmlUnitContextAction.run(JavaScriptEngine.java:949) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:836) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:812) 在com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:800) 在com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:910) 在com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:878) at com.softsolutions.subagent.api.model.MainAPIConfiguration $$ M $ a1d673a.getOgeroContent(MainAPIConfiguration.java:190) at com.softsolutions.subagent.api.model.MainAPIConfiguration $$ M $ a1d673a.doCompose(MainAPIConfiguration.java:105) at com.softsolutions.subagent.api.model.MainAPIConfiguration $$ A $ a1d673a.doCompose() at com.softsolutions.subagent.api.model.MainAPIConfiguration.doCompose() at com.softsolutions.common.base.ui.composer.SoftSolComposer.doAfterCompose(SoftSolComposer.java:163) at com.softsolutions.subagent.api.model.MainAPIConfiguration.doAfterCompose() 在org.zkoss.zk.ui.impl.CreateInfo.doAfterCompose(UiEngineImpl.java:2598) at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:881) 在org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:826) 在org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:735) 在org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:699) 在org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:442) 在org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:356) 在org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215) 在org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:136) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) 在org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) 在org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) 在org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) 在org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) 在org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) 在org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603) 在java.lang.Thread.run(Thread.java:722) 引起:java.lang.NoClassDefFoundError:无法初始化类com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectImpl 在com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject.jsConstructor(ActiveXObject.java:123) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:601) at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153) ... 99更多
答案 0 :(得分:0)
这已经解决了。看来我应该更改jacob.jar的.dll文件的位置。它被放在web-inf / lib下。我把它移到tomcat / bin位置,效果很好。