java gwt htmlunit gwtp

java - ¿Por qué HTMLUnit siempre muestra la página de host sin importar qué url escriba(aplicación de GWT rastreable)?



gwtp (1)

Aquí está el código completo

public class CrawlServlet implements Filter{ public static String getFullURL(HttpServletRequest request) { StringBuffer requestURL = request.getRequestURL(); String queryString = request.getQueryString(); if (queryString == null) { return requestURL.toString(); } else { return requestURL.append(''?'').append(queryString).toString(); } } @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String fullURLQueryString = getFullURL(httpRequest); System.out.println(fullURLQueryString+" what wrong"); if ((fullURLQueryString != null) && (fullURLQueryString.contains("_escaped_fragment_"))) { // remember to unescape any %XX characters fullURLQueryString=URLDecoder.decode(fullURLQueryString,"UTF-8"); // rewrite the URL back to the original #! version String url_with_hash_fragment=fullURLQueryString.replace("?_escaped_fragment_=", "#!"); final WebClient webClient = new WebClient(); WebClientOptions options = webClient.getOptions(); options.setCssEnabled(false); options.setThrowExceptionOnScriptError(false); options.setThrowExceptionOnFailingStatusCode(false); options.setJavaScriptEnabled(false); HtmlPage page = webClient.getPage(url_with_hash_fragment); // important! Give the headless browser enough time to execute JavaScript // The exact time to wait may depend on your application. webClient.waitForBackgroundJavaScript(20000); // return the snapshot //String originalHtml=page.getWebResponse().getContentAsString(); //System.out.println(originalHtml+" +++++++++"); System.out.println(page.asXml()+" +++++++++"); PrintWriter out = response.getWriter(); out.println(page.asXml()); //out.println(originalHtml); } else { try { // not an _escaped_fragment_ URL, so move up the chain of servlet (filters) chain.doFilter(request, response); } catch (ServletException e) { System.err.println("Servlet exception caught: " + e); e.printStackTrace(); } } } @Override public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub } }

Después de abrir la url " http://127.0.0.1:8888/Myproject.html?gwt.codesvr=127.0.0.1:9997?_escaped_fragment_=article ", mostró el código html de la página de host de esta manera:

<html> <head> <meta name="fragment" content="!"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <!-- --> <!-- Consider inlining CSS to reduce the number of requested files --> <!-- --> <link type="text/css" rel="stylesheet" href="MyProject.css"/> <!-- --> <!-- Any title is fine --> <!-- --> <title>MyProject</title> <!-- --> <!-- This script loads your compiled module. --> <!-- If you add any GWT meta tags, they must --> <!-- be added before this line. --> <!-- --> <script type="text/javascript" language="javascript" ></script> <!-- --> <!-- The body can have arbitrary html, or --> <!-- you can leave the body empty if you want --> <!-- to create a completely dynamic UI. --> <!-- --> </head> <body> <div id="loading"> Loading <br/> <img src="../images/loading.gif"/> </div> <!-- OPTIONAL: include this if you want history support --> <iframe src="javascript:''''" id="__gwt_historyFrame" tabindex="-1" style="position: absolute; width: 0;height: 0; border:0;"></iframe> <!-- RECOMMENDED if your web app will not function without JavaScript enabled --> <noscript> <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1pxsolid red; padding: 4px; font-family: sans-serif;"> Your web browser must have JavaScript enabled in order for this application to display correctly. </div> </noscript> </body> </html>

Por otro lado, " http://127.0.0.1:8888/Myproject.html?gwt.codesvr=127.0.0.1:9997#!article " funciona bien y muestra el artículo sin ningún problema.

También compilé todo el proyecto y lo ejecuté bajo Tomcat7, pero tengo el mismo problema. Siempre muestra el html de la página de host.

Nota: la página del artículo es el presentador anidado que está incrustado dentro de un presentador de encabezado. Pero no creo que esa sea la razón principal porque ni siquiera mostró la página del encabezado.


Primero, en vez de ?_escaped_fragment_=article , tal vez intente con &_escaped_fragment_=article porque ya lo tiene ? para el gwt.codesvr , entonces 2 ? puede estropear el análisis de parámetros url.

En segundo lugar, debe asegurarse de que su filtro maneje el caso de tener el parámetro gwt.codesvr . Parece que su filtro supone que es el primer parámetro, es decir, ¿comienza con ? . Creo que el ejemplo aquí funciona de cualquier manera.