简体   繁体   English

为Java Servlet创建服务器端方法

[英]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 我只是通过使用以下示例通过Java servlet编写了教程: 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. 对我而言尚不清楚的是,开发人员如何在此Servlet中实现可由客户端调用的方法。 The doGet method is where the http request lands. doGet方法是http请求到达的地方。 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? 还是Java servlet可以在客户端调用中包装方法和方法参数的“内置”方式?

implement methods inside this servlet that can be called by a client : the client does not call the servlet method at all. implement methods inside this servlet that can be called by a client端调用的方法:客户端根本不调用Servlet方法。 It is the server that routes a HTTP request to a certain piece of code, the servlet's GET, POST, etc method. 是服务器将HTTP请求routes到特定代码段,即Servlet的GET,POST等方法。

The servlet container is hit with an GET method on a URL like /my/servlet/info . 该servlet容器在/my/servlet/info类的URL上使用GET方法命中。 The URL ist translated into a servlet (by the servlet's path) and then the servlet's get method is called. URL ist转换为servlet(通过servlet的路径),然后调用servlet的get方法。 Based on the URl the servlet container decides what servlet to use. 基于UR1,servlet容器决定使用哪个servlet。

In general, a servlet is just an endpoint, usually an HTTP endpoint. 通常,servlet只是一个端点,通常是HTTP端点。 It looks to me that you don't want to serve raw HTTP; 在我看来,您不想提供原始HTTP; have a look into JAX-RS ( tutorial ). 看一下JAX-RS( 教程 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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