(From a servlet on the server)
To call the call enqueue servlet without using html code, you use a RequestDispatcher and forward the request.
String enqueueURL = "/enqueue";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(destination);
dispatcher.forward(request, response);
To sent a List to another servlet, use request.setAttribute
request.setAttribute("myList", list);
To obtain it in a different servlet, use request.getAttribute
List value = (List)request.getAttribute("myList")
From a design perspective, if your servlet is functioning as a Controller such as in a Model-View-Controller system, then it's use is appropriate.
(from GWT client side code)
Simply make an RPC call and in the method that handles it put your queue code:
public class MyServiceImpl extends RemoteServiceServlet implements
MyService {
public void myMethod(String key) {
Queue queue = QueueFactory.getDefaultQueue();
byte[] buf;
TaskOptions taskOptions= TaskOptions.Builder.withUrl("/tasks/worker").method(Method.POST);
taskOptions.payload(buf);
queue.add(taskOptions);
}
}
If you need help converting the List to a byte[], see this or something like it (i.e. coverting a Java Object to an byte[] array ..don't forget to include a cast to get it back into a List)
To call a servlet from client code in GWT, simply use a RequestBuilder
import com.google.gwt.http.client.*;
...
String url = "http://www.myurl.com/enqueue";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
try {
Request request = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
// Couldn't connect to server (could be timeout, SOP violation, etc.)
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
// Process the response in response.getText()
} else {
// Handle the error. Can get the status text from response.getStatusText()
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
}
See GWT Docs on RequestBuilder