Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT - making GET requests

Tags:

gwt

Simple question. I need to make a GET request in GWT that redirects to a new page, but I can't find the right API.

Is there one? I am supposed to simply form the URL myself and then do Window.Location.replace?

(The reason is that I want my search page to be linkable)

Thanks.

(and sorry for not making my question clear enough, initially)

like image 702
Chris Avatar asked Jun 01 '09 15:06

Chris


4 Answers

have a look at 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("/");
    }
}
like image 199
Silfverstrom Avatar answered Oct 31 '22 20:10

Silfverstrom


GWT does not prohibit you from using regular servlets.

You can declare a servlet in your 'web.xml' file:

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

and then you can implement your Servlet:

public class MyServlet extends HttpServlet {

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

      // your code here

}

}
like image 29
ivo Avatar answered Oct 31 '22 20:10

ivo


Redirecting to a new page is done with Window.Location.replace.

Multiple pages should be handled using the history mechanism.

like image 34
Chris Avatar answered Oct 31 '22 19:10

Chris


If you are opening a separate window, it is easy:

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

Otherwise, use RequestBuilder as Silfverstrom suggests.

like image 1
Gene Gotimer Avatar answered Oct 31 '22 19:10

Gene Gotimer