Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to create 5 methods on the server side, which will work with binary data. The remote clients are applet and JavaScript. The Client will send files to the server, and the server must parse these files and then return the response as XML/JSON.

So I am confused - is it good practice to use REST-service in this case? Or should I use a servlet?

My colleague told me:

"Creating REST-service that will be used only by one Application isn't good. REST must be created only when it will be used by many apps. And REST has some disadvantages over servlet: REST is slower than servlet; it more difficult to write thread-safe REST than servlet"

However, I see some disadvantages with using Servlet: I need to send a function name that I want to call (i.e. as extra HTTP parameter send function name) and then inside the doPost method perform the following switch:

switch(functionName) {
 case "function1":
   function1(); 
   break;
 case "function2"
   function2(); 
   break;
//.... more `case` statements....

}

In case of REST I can simple use different URLs for different functions. Also, in the case of REST, it more convenient to return JSON/XML from server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
108 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are confusing two paradigms here:

  • REST is a software architecture “style”;
  • Servlet is a server-side technology.

You can, for example, implement REST-like services using Servlets.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...