开发者

Multiple servlets

开发者 https://www.devze.com 2023-02-15 07:04 出处:网络
Is it better to have one servlet running multiple tasks, or have mu开发者_StackOverflow社区ltiple servlets?

Is it better to have one servlet running multiple tasks, or have mu开发者_StackOverflow社区ltiple servlets?

eg. At the moment i have it like this:

ViewCarsServlet CarViewSalesServlet AddCarSaleServlet

With each serlvet handliling my requests.

But would it be better to have obne such as CarServlet. And then pass a Task variable into a If statement?

Which would be better coding practice?


It's better to have multiple servlets for multiple task. it will not affect performance as well as it is more user friendly, for a particular task we can hit separate servlet instead of making one servlet complex with lot of if else conditions, if we using only one servlet every time we need to check the conditions and then execute the respective task.


Define "better".

My personal taste would group related operations into a single servlet. I'd think about it as exposing a REST API of operations that went together. But that's just my personal opinion. I don't know of a "right" answer that everyone would agree to.

0

精彩评论

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