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)
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("/");
}
}
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
}
}
Redirecting to a new page is done with Window.Location.replace.
Multiple pages should be handled using the history mechanism.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With