2009-06-01 10 views
11

Domanda semplice. Devo effettuare una richiesta GET in GWT che reindirizzi a una nuova pagina, ma non riesco a trovare l'API corretta.GWT - richieste GET

C'è uno? Dovrei semplicemente creare l'URL da solo e poi fare Window.Location.replace?

(il motivo è che voglio che la mia pagina di ricerca per essere collegabili)

Grazie.

(e scusa per non fare la mia domanda abbastanza chiaro, inizialmente)

+0

Credo che la mia domanda si riduce a: Come posso avere più pagine utilizzando GWT? – Chris

+0

cosa intendi per "pagine multiple"? – Chii

risposta

2

Il reindirizzamento a una nuova pagina viene effettuato con Window.Location.replace.

Più pagine devono essere gestite utilizzando il meccanismo cronologico.

12

uno sguardo al http://library.igcar.gov.in/readit2007/tutori/tools/gwt-windows-1.4.10/doc/html/com.google.gwt.http.client.html

public class GetExample implements EntryPoint { 

    public static final int STATUS_CODE_OK = 200; 

    public static void doGet(String url) { 
     RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); 

     try { 
      Request response = builder.sendRequest(null, new RequestCallback() { 
       public void onError(Request request, Throwable exception) { 
        // Code omitted for clarity 
       } 

       public void onResponseReceived(Request request, Response response) { 
        // Code omitted for clarity 
       } 
      }); 

     } catch (RequestException e) { 
      // Code omitted for clarity 
     } 
    } 

    public void onModuleLoad() { 
     doGet("/"); 
    } 
} 
2

GWT non ti vieta di utilizzare servlet regolari.

È possibile dichiarare una servlet nel file 'web.xml':

<servlet> 
    <servlet-name>myServlet</servlet-name> 
    <servlet-class>org.myapp.server.MyServlet</servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>myServlet</servlet-name> 
    <url-pattern>/myurl/*</url-pattern> 
</servlet-mapping> 

e quindi è possibile implementare il Servlet:

public class MyServlet extends HttpServlet { 

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws 
     IOException { 

     // your code here 

} 

} 
1

Se si sta aprendo una finestra separata, è facile:

Window.open(url, windowName, "resizable=yes,scrollbars=yes,menubar=yes,location=yes,status=yes"); 

Altrimenti, utilizzare RequestBuilder come suggerisce Silfverstrom.

0

Simile a answer from ivo. Posso farlo nel mio telaio todomvc GWT con filter mapping anziché mappatura servlet nel file web.xml.

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     version="2.5" 
     xmlns="http://java.sun.com/xml/ns/javaee"> 

    <filter> 
    <filter-name>guiceFilter</filter-name> 
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> 
    </filter> 

    <filter-mapping> 
    <filter-name>guiceFilter</filter-name> 
    <url-pattern>/myurl/*</url-pattern> 
    </filter-mapping> 

    <listener> 
    <listener-class>com.todomvc.server.ToDoServerInjector</listener-class> 
    </listener> 

    <!-- Default page to serve --> 
    <welcome-file-list> 
    <welcome-file>GwtGaeChannelToDo.html</welcome-file> 
    </welcome-file-list> 

</web-app>