开发者

how to invoke servlet from the client code in gwt

66305 HI, I want to invoke a Servlet from the client side, as a Onclick event on a Button in java programming language. I开发者_StackOverflow中文版 read somewhere through anchor tag we can call a servlet, but i did not figure out the solution or Syntax properly.

Anyone please me.

Thanks, sekhar


Typically you use a RemoteService to communicate with a server. To do that, you create an interface that extends RemoteService and an implementation on the server that implements that interface and extends RemoteServiceServlet. All that is described in more detail here. If you need to make a call to some servlet that isn't a remote service servlet, you can use RequestBuilder to send an HTTP request to that servlet's URL.

An Anchor is basically just a normal HTML <a> tag which could link to the URL of a servlet.


You have to manually create one httpClient & call GET/POST method.

Below is sample code using POST method:

//---

    HttpClient client = new HttpClient();

    BufferedReader br = null;

    PostMethod method = new PostMethod("http://someUrl.com");
    method.addParameter("p", "\"parameter\"");

    int statusCode = client.executeMethod(method);

    if(statusCode == HttpStatus.SC_NOT_IMPLEMENTED) {
         System.out.println("Not Supported");
         method.getResponseBodyAsString();
    } else {
         br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
         String readLine;
         while(((readLine = br.readLine()) != null)) {
              System.out.println(readLine);
          }
    }

//---
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜