简体   繁体   中英

Creating server side methods for a Java servlet

I just went through the tutorial on writing a Java servlet using the example at: http://www.vogella.com/tutorials/EclipseWTP/article.html

What isn't clear to me is how developers implement methods inside this servlet that can be called by a client. The doGet method is where the http request lands. One way is to pass in a querystring, post body or header that contains information indicating a method to execute and then just create a class with methods to carry out based upon which method was indicated.

Or is there a more "built-in" way that a Java servlet can wrap methods and method parameters in the client call?

implement methods inside this servlet that can be called by a client : the client does not call the servlet method at all. It is the server that routes a HTTP request to a certain piece of code, the servlet's GET, POST, etc method.

The servlet container is hit with an GET method on a URL like /my/servlet/info . The URL ist translated into a servlet (by the servlet's path) and then the servlet's get method is called. Based on the URl the servlet container decides what servlet to use.

In general, a servlet is just an endpoint, usually an HTTP endpoint. It looks to me that you don't want to serve raw HTTP; have a look into JAX-RS ( tutorial ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM