2009-06-01 66 views
11

简单的问题。我需要在GWT 中发出GET请求,该请求会重定向到新页面,但我无法找到正确的API。GWT - 制作GET请求

有没有?我应该自己简单地形成网址,然后做Window.Location.replace

(原因是,我想我的搜索页面可链接)

感谢。

(并没有使我的问题不够清楚,最初对不起)

+0

我想我的问题归结为: 如何我一直在使用GWT多页? – Chris 2009-06-01 20:55:38

回答

2

使用Window.Location.replace完成重定向到新页面。

应使用历史记录机制处理多个页面。

12

看看 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不使用常规的servlet禁止你。

您可以在 'web.xml中' 文件中声明一个servlet:

<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> 

,然后你可以实现你的servlet:

public class MyServlet extends HttpServlet { 

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

     // your code here 

} 

} 
1

如果打开一个单独的窗口,它是易:

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

否则,使用RequestBuilder作为Silfverstrom建议。

0

answer from ivo类似。我可以在我的GWT todomvc框架中使用filter mapping而不是web.xml文件中的servlet映射来完成此操作。

<?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>